Sha256: 0235b7470b7800c31270f88a86baa28ac1b37d0061251a504b3883f904366402

Contents?: true

Size: 1.23 KB

Versions: 14

Compression:

Stored size: 1.23 KB

Contents

package sh.calaba.instrumentationbackend.actions.webview;

import sh.calaba.instrumentationbackend.InstrumentationBackend;
import sh.calaba.instrumentationbackend.Result;
import sh.calaba.instrumentationbackend.actions.Action;
import android.webkit.WebView;

public class ExecuteJavascript implements Action {

	@Override
	public Result execute(String... args) {

		CalabashChromeClient ccc = CalabashChromeClient.findAndPrepareWebViews().get(0);
		final WebView webView = ccc.getWebView();
		final String script = "javascript:(function() {"
				+ " var r;"
				+ " try {"
				+ "  r = (function() {"
				+ args[0] + ";"
				+ "  }());"
				+ " } catch (e) {"
				+ "  r = 'Exception: ' + e;"
				+ " }"
				+ " prompt('calabash:'+r);" 
				+ "}())";

		System.out.println("execute javascript: " + script);
		
		InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(
				new Runnable() {
					@Override
					public void run() {
						webView.loadUrl(script);
					}
				});

		String r = ccc.getResult();
		System.out.println("javascript result: " + r);

		boolean success = true;
		if (r.startsWith("Exception:")) {
			success = false;
		}

		return new Result(success, r);
	}

	@Override
	public String key() {
		return "execute_javascript";
	}

}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
calabash-android-0.3.0.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.22 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.21 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.20 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.19 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.18 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.17 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.16 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.15 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.14 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.13 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.12 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.2.11 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java