Sha256: e4ca383b15d7c38c891f179ff09e3c07f352023003be5dfa852d9420dbd21cbf

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 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);
		WebView webView = ccc.getWebView();
		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);
        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 & 2 rubygems

Version Path
calabash-android-0.4.0.pre6 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.4.0.pre5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.4.0.pre4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.4.0.pre3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
testautoa-0.4.0 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.4.0.pre2 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.4.0.pre1 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.8 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.7 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.6 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.4 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.3 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
calabash-android-0.3.3.pre5 test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java