Sha256: 5889165f55337b8086e39d359dc9a330d9f8847ee2336ca92f886c79242e00a3

Contents?: true

Size: 1.38 KB

Versions: 19

Compression:

Stored size: 1.38 KB

Contents

package sh.calaba.instrumentationbackend.actions.webview;

import java.util.List;

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) {

		List<CalabashChromeClient> list = CalabashChromeClient.findAndPrepareWebViews();
		if (list.isEmpty()) {
			return new Result(false, "No WebView component found");
		}
		
		CalabashChromeClient ccc = list.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

19 entries across 19 versions & 1 rubygems

Version Path
calabash-android-0.3.3.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.3.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.3.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.2.pre5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.2.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.2.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.2.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.2.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre10 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre9 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre8 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre7 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre6 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.0.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java