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