calabash-android 0.4.22.pre4 → 0.5.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/bin/calabash-android +66 -45
  3. data/lib/calabash-android/calabash_steps.rb +0 -8
  4. data/lib/calabash-android/canned_steps.md +2 -30
  5. data/lib/calabash-android/lib/TestServer.apk +0 -0
  6. data/lib/calabash-android/operations.rb +199 -23
  7. data/lib/calabash-android/removed_actions.txt +52 -0
  8. data/lib/calabash-android/steps/assert_steps.rb +9 -24
  9. data/lib/calabash-android/steps/check_box_steps.rb +2 -2
  10. data/lib/calabash-android/steps/context_menu_steps.rb +11 -4
  11. data/lib/calabash-android/steps/date_picker_steps.rb +2 -2
  12. data/lib/calabash-android/steps/enter_text_steps.rb +13 -13
  13. data/lib/calabash-android/steps/l10n_steps.rb +5 -5
  14. data/lib/calabash-android/steps/map_steps.rb +12 -12
  15. data/lib/calabash-android/steps/navigation_steps.rb +12 -12
  16. data/lib/calabash-android/steps/press_button_steps.rb +16 -12
  17. data/lib/calabash-android/steps/progress_steps.rb +19 -22
  18. data/lib/calabash-android/steps/search_steps.rb +2 -2
  19. data/lib/calabash-android/steps/spinner_steps.rb +10 -2
  20. data/lib/calabash-android/steps/time_picker_steps.rb +2 -2
  21. data/lib/calabash-android/version.rb +1 -1
  22. data/lib/calabash-android/wait_helpers.rb +29 -1
  23. data/test-server/instrumentation-backend/antlr/UIQuery.g +11 -11
  24. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/CalabashInstrumentationTestRunner.java +3 -2
  25. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +9 -4
  26. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +16 -12
  27. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/application/Backdoor.java +55 -0
  28. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/LongPressCoordinate.java +19 -2
  29. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptExecuter.java +105 -0
  30. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/QueryHelper.java +27 -30
  31. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +27 -18
  32. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/ComparisonOperator.java +7 -1
  33. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTPredicate.java +16 -4
  34. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +13 -6
  35. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +94 -48
  36. metadata +5 -59
  37. data/lib/calabash-android/steps/additions_manual_steps.rb +0 -11
  38. data/lib/calabash-android/steps/app_steps.rb +0 -10
  39. data/lib/calabash-android/steps/list_steps.rb +0 -41
  40. data/lib/calabash-android/steps/rotation_steps.rb +0 -7
  41. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressButtonNumber.java +0 -22
  42. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressButtonText.java +0 -27
  43. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressImageButtonDescription.java +0 -39
  44. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressImageButtonNumber.java +0 -22
  45. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/WaitForButton.java +0 -47
  46. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/checkbox/ToggleCheckboxNumber.java +0 -22
  47. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressText.java +0 -22
  48. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuById.java +0 -26
  49. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuByIndex.java +0 -22
  50. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuByText.java +0 -26
  51. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/helpers/InspectCurrentDialog.java +0 -76
  52. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListData.java +0 -85
  53. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemProperties.java +0 -194
  54. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemText.java +0 -136
  55. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/LongPressListItems.java +0 -22
  56. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/PressListItems.java +0 -22
  57. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/scrolling/ScrollDown.java +0 -22
  58. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/scrolling/ScrollUp.java +0 -22
  59. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/search/EnterQueryByIndex.java +0 -29
  60. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/SelectFromMenuByText.java +0 -24
  61. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/spinner/GetSelectedSpinnerItemText.java +0 -36
  62. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/spinner/SelectSpinnerItemByContentDescription.java +0 -43
  63. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertGridViewContainsNoDuplicates.java +0 -72
  64. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertText.java +0 -31
  65. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertTextOfSpecificTextViewByContentDescription.java +0 -32
  66. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextById.java +0 -30
  67. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextByIndex.java +0 -22
  68. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextFieldByContentDescription.java +0 -33
  69. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClickOnText.java +0 -22
  70. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextByContentDescription.java +0 -32
  71. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextById.java +0 -33
  72. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextByIndex.java +0 -22
  73. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/GetTextById.java +0 -42
  74. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/AssertViewProperty.java +0 -141
  75. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/ClickOnViewByDescription.java +0 -46
  76. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/ClickOnViewById.java +0 -56
  77. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +0 -101
  78. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/HasView.java +0 -31
  79. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/IsEnabled.java +0 -30
  80. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/LongPressOnViewById.java +0 -34
  81. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/Press.java +0 -89
  82. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/SelectTab.java +0 -110
  83. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/Wait.java +0 -24
  84. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForDialogClose.java +0 -21
  85. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForProgress.java +0 -47
  86. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForScreen.java +0 -54
  87. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForTab.java +0 -108
  88. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForText.java +0 -37
  89. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForView.java +0 -43
  90. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForViewById.java +0 -58
  91. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptOperation.java +0 -44
  92. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/PressByCssSelector.java +0 -70
  93. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java +0 -64
@@ -1,108 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.wait;
2
-
3
- import java.util.List;
4
-
5
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
6
- import sh.calaba.instrumentationbackend.Result;
7
- import sh.calaba.instrumentationbackend.actions.Action;
8
- import android.os.SystemClock;
9
- import android.util.Log;
10
- import android.view.View;
11
- import android.widget.TabHost;
12
- import android.widget.TextView;
13
-
14
- /**
15
- * Waits for a tab by name
16
- *
17
- * @author Nicholas Albion
18
- */
19
- public class WaitForTab implements Action {
20
-
21
- @Override
22
- public Result execute(String... args) {
23
-
24
- final int DEFAULT_TIMEOUT = 5 * 1000;
25
- int timeout = DEFAULT_TIMEOUT;
26
-
27
- switch (args.length) {
28
- case 0:
29
- return new Result(false, "Cannot check for correct screen. No tab name supplied!");
30
- case 1: {
31
- return waitForTab( args[0], DEFAULT_TIMEOUT );
32
- }
33
- case 2: { // 1st arg is Activity name, 2nd arg is timeout
34
- try {
35
- timeout = Integer.parseInt(args[1]);
36
- } catch (NumberFormatException e) {
37
- return new Result(false, "Invalid timeout supplied. Should be an integer!");
38
- }
39
- return waitForTab( args[0], timeout );
40
- }
41
- default:
42
- return new Result(false, "Too many argument supplied to wait_for_tab!");
43
- }
44
- }
45
-
46
- private Result waitForTab( String tabName, int timeout ) {
47
- int tabHostIndex = 0;
48
- long startTime = SystemClock.uptimeMillis();
49
- // TabHost tabHost = InstrumentationBackend.solo.getView( TabHost.class, tabHostIndex ); // waits 10 seconds
50
-
51
- if( InstrumentationBackend.solo.waitForView( TabHost.class, 1, timeout ) ) {
52
- TabHost tabHost = (TabHost)InstrumentationBackend.solo.getView(TabHost.class, tabHostIndex);
53
-
54
- boolean tabFound = false;
55
- int numberOfTabs = tabHost.getChildCount();
56
- for( int i = 0; i < numberOfTabs; i++ ) {
57
- if( tabName.equals( tabHost.getTag(i) ) ) {
58
- tabFound = true;
59
- break;
60
- }
61
- }
62
- if( tabFound == false ) {
63
- Log.w("WaitForTab", "Tab was not found: " + tabName);
64
- // return new Result(false, "Tab " + tabName + " not found");
65
- }
66
-
67
- String currentTab;
68
- do {
69
- int tabIndex = tabHost.getCurrentTab();
70
- View view = tabHost.getTabWidget().getChildTabViewAt(tabIndex);
71
- if( view instanceof TextView ) {
72
- currentTab = ((TextView)view).getText().toString();
73
- if( tabName.equals(currentTab) ) {
74
- return new Result(true, "The current tab text view matches");
75
- }
76
- } else {
77
- Log.i("WaitForTab", "current tab view: " + view.getId() + ", " + view.getClass().getSimpleName());
78
- List<TextView> textViews = InstrumentationBackend.solo.getCurrentViews(TextView.class, view);
79
- for( TextView textView : textViews ) {
80
- currentTab = textView.getText().toString();
81
- Log.i("WaitForTab", " child text view: " + currentTab);
82
- if( tabName.equals(currentTab) ) {
83
- return new Result(true, "The current tab text view matches");
84
- }
85
- }
86
- }
87
-
88
- currentTab = tabHost.getCurrentTabTag();
89
-
90
- if( tabName.equals(currentTab) ) {
91
- return new Result(true, "The current tab's tag matches");
92
- }
93
- try {
94
- Thread.sleep(500);
95
- } catch (InterruptedException e) {}
96
- } while( (SystemClock.uptimeMillis() - startTime) < timeout );
97
-
98
- return new Result(false, "The current tab is: " + currentTab + ", was tab even found? " + tabFound);
99
- } else {
100
- return new Result(false, "Timed out waiting for a TabActivity. Current activity is " + InstrumentationBackend.solo.getCurrentActivity().getLocalClassName());
101
- }
102
- }
103
-
104
- @Override
105
- public String key() {
106
- return "wait_for_tab";
107
- }
108
- }
@@ -1,37 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.wait;
2
-
3
-
4
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
- import sh.calaba.instrumentationbackend.Result;
6
- import sh.calaba.instrumentationbackend.actions.Action;
7
-
8
-
9
- public class WaitForText implements Action {
10
-
11
- @Override
12
- public Result execute(String... args) {
13
-
14
- int timeout = 90 * 1000;
15
- if (args.length > 1) { // a second argument is a timeout
16
- try {
17
- // the argument is in seconds but robotium takes milliseconds
18
- timeout = 1000 * Integer.parseInt(args[1]);
19
- } catch (NumberFormatException e) {
20
- return new Result(false, "Invalid timeout supplied. Should be an integer.");
21
- }
22
- }
23
-
24
- boolean timedOut = !InstrumentationBackend.solo.waitForText(args[0], 1, timeout);
25
- if(timedOut) {
26
- return new Result(false, "Time out while waiting for text:" + args[0]);
27
- } else {
28
- return Result.successResult();
29
- }
30
-
31
- }
32
-
33
- @Override
34
- public String key() {
35
- return "wait_for_text";
36
- }
37
- }
@@ -1,43 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.wait;
2
-
3
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
4
- import sh.calaba.instrumentationbackend.Result;
5
- import sh.calaba.instrumentationbackend.TestHelpers;
6
- import sh.calaba.instrumentationbackend.actions.Action;
7
- import android.view.View;
8
-
9
- public class WaitForView implements Action {
10
-
11
- @Override
12
- public Result execute(String... args) {
13
- String text = args[0];
14
- long endTime = System.currentTimeMillis() + 60000;
15
- while (System.currentTimeMillis() < endTime) {
16
- if (InstrumentationBackend.solo.searchButton(text) || searchForViewWithContentDescription(text)) {
17
- return Result.successResult();
18
- } else {
19
- try {
20
- Thread.sleep(500);
21
- } catch (InterruptedException e) {
22
- return Result.fromThrowable(e);
23
- }
24
- }
25
- }
26
- return new Result(false, "Timed out while waiting for view with text or contentDescription:'" + text + "'");
27
- }
28
-
29
- @Override
30
- public String key() {
31
- return "wait_for_view";
32
- }
33
-
34
- private boolean searchForViewWithContentDescription(String description) {
35
- View view = TestHelpers.getViewByDescription(description);
36
- if (view != null) {
37
- return true;
38
- } else {
39
- return false;
40
- }
41
- }
42
-
43
- }
@@ -1,58 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.wait;
2
-
3
-
4
- import sh.calaba.instrumentationbackend.Result;
5
- import sh.calaba.instrumentationbackend.TestHelpers;
6
- import sh.calaba.instrumentationbackend.actions.Action;
7
- import android.view.View;
8
-
9
-
10
- public class WaitForViewById implements Action {
11
-
12
- @Override
13
- public Result execute(String... args) {
14
- String viewId = args[0];
15
-
16
- try {
17
- if( getViewById(viewId, 60000) != null ) {
18
- return Result.successResult();
19
- } else {
20
- return new Result(false, "Waiting for view with id '" + viewId + "' to be visible timed out");
21
- }
22
- } catch( InterruptedException e ) {
23
- return Result.fromThrowable(e);
24
- }
25
- }
26
-
27
- protected View getViewById( String viewId, long timeout ) throws InterruptedException {
28
-
29
- System.out.println("Waiting for view with id '" + viewId + "' to appear");
30
-
31
- View view = TestHelpers.getViewById(viewId);
32
-
33
- // no view, quick exit
34
- if(view == null){
35
- throw new IllegalArgumentException("Could not find view with id '" + viewId + "'");
36
- }
37
-
38
- System.out.println("Waiting for view with id '" + viewId + "' found view " + view);
39
-
40
- long endTime = System.currentTimeMillis() + timeout;
41
- while (System.currentTimeMillis() < endTime) {
42
- if (view.getVisibility() == View.VISIBLE) {
43
- System.out.println("View with id '" + viewId + "' is visible, success");
44
- return view;
45
- } else {
46
- System.out.println("View with id '" + viewId + "' is not visible, sleeping...");
47
- Thread.sleep(500);
48
- }
49
- }
50
-
51
- return null;
52
- }
53
-
54
- @Override
55
- public String key() {
56
- return "wait_for_view_by_id";
57
- }
58
- }
@@ -1,44 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.webview;
2
-
3
- import sh.calaba.instrumentationbackend.query.Operation;
4
-
5
- public class JavaScriptOperation implements Operation {
6
-
7
- public final String script;
8
- public final String arg;
9
-
10
- public JavaScriptOperation(String script, String args) {
11
- this.script = script;
12
- this.arg = args;
13
- }
14
-
15
- @SuppressWarnings("unchecked")
16
- @Override
17
- public Object apply(Object o) {
18
- throw new UnsupportedOperationException("asd");
19
- /*
20
- Map<String, Object> domEl = (Map<String, Object>) o;
21
-
22
- WebView webView = (WebView) domEl.get("webView");
23
-
24
- domEl.remove("class");
25
- domEl.remove("html");
26
- domEl.remove("webView");
27
-
28
- String elJson = QueryHelper.toJsonString(domEl);
29
-
30
-
31
- WebFuture asyncRes = QueryHelper.executeAsyncJavascriptInWebviews(webView, this.script,
32
- elJson, this.arg);
33
- return asyncRes.getAsString();
34
- */
35
- }
36
-
37
- @Override
38
- public String getName() {
39
- return "JSOp[script="+this.script+"]";
40
- }
41
-
42
-
43
-
44
- }
@@ -1,70 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.webview;
2
-
3
-
4
- import java.util.ArrayList;
5
- import java.util.List;
6
- import java.util.concurrent.Callable;
7
-
8
- import sh.calaba.instrumentationbackend.Result;
9
- import sh.calaba.instrumentationbackend.actions.Action;
10
- import sh.calaba.instrumentationbackend.actions.webview.CalabashChromeClient.WebFuture;
11
- import sh.calaba.instrumentationbackend.query.ast.UIQueryUtils;
12
- import android.webkit.WebView;
13
-
14
- @Deprecated
15
- public class PressByCssSelector implements Action {
16
-
17
- @SuppressWarnings({ "unchecked", "rawtypes" })
18
- @Override
19
- public Result execute(final String... args) {
20
- List<WebFuture> webResults = (List<WebFuture>) UIQueryUtils.evaluateSyncInMainThread(new Callable() {
21
-
22
- public Object call() throws Exception {
23
-
24
- List<WebFuture> webResults = new ArrayList();
25
- for (CalabashChromeClient ccc : CalabashChromeClient.findAndPrepareWebViews()) {
26
- WebView webView = ccc.getWebView();
27
-
28
- webView.loadUrl("javascript:(function() {" +
29
- "var element = document.querySelector(\"" + args[0] + "\");" +
30
- "if (element != null) {" +
31
- " var oEvent = document.createEvent ('MouseEvent');" +
32
- " oEvent.initMouseEvent('click', true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, element);" +
33
- " element.dispatchEvent( oEvent );" +
34
- " prompt('calabash:true');" +
35
- " return;" +
36
- "}" +
37
- "prompt('calabash:false');" +
38
- "})()");
39
-
40
- webResults.add(ccc.getResult());
41
- }
42
- return webResults;
43
-
44
- }
45
- });
46
-
47
- List<String> allResults = new ArrayList<String>(webResults.size());
48
- boolean success = false;
49
- for (WebFuture f : webResults) {
50
- String result = f.getAsString();
51
- allResults.add(result);
52
- if ("true".equals(result)) {
53
- success = true;
54
- }
55
- }
56
-
57
- if (allResults.size() == 0) {
58
- return new Result(false, "No WebView found");
59
- }
60
- else {
61
- return new Result(success, allResults);
62
- }
63
- }
64
-
65
- @Override
66
- public String key() {
67
- return "click_by_selector";
68
- }
69
-
70
- }
@@ -1,64 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.webview;
2
-
3
-
4
- import android.webkit.WebView;
5
-
6
- import java.util.Map;
7
- import java.util.concurrent.Callable;
8
-
9
- import sh.calaba.instrumentationbackend.Result;
10
- import sh.calaba.instrumentationbackend.actions.Action;
11
- import sh.calaba.instrumentationbackend.query.QueryResult;
12
- import sh.calaba.instrumentationbackend.query.ast.UIQueryUtils;
13
-
14
-
15
- public class SetText implements Action {
16
-
17
- /**
18
- * args[0]: Selector type "xpath" or "css"
19
- * args[1]: xpath or css selector
20
- * args[2]: text to enter into the first selected element
21
- */
22
- @SuppressWarnings({ "rawtypes", "unchecked"})
23
- @Override
24
- public Result execute(final String... args) {
25
- String query = args[1];
26
- if (!query.startsWith("'")) {
27
- query = "'" + query;
28
- }
29
- if (!query.endsWith("'")) {
30
- query = query + "'";
31
- }
32
-
33
- final String uiQuery = "android.webkit.WebView " + args[0] + ":" + query;
34
- QueryResult queryResult = new sh.calaba.instrumentationbackend.query.Query(uiQuery).executeQuery();
35
- if (queryResult.isEmpty()) {
36
- return Result.failedResult("No element found: " + query);
37
- }
38
- Map<String, Object> firstElement = QueryHelper.findFirstVisibleElement(queryResult.getResult());
39
- firstElement.remove("class");
40
- firstElement.remove("html");
41
- final WebView webView = (WebView) firstElement.remove("webView");
42
-
43
- final String firstElementJson = QueryHelper.toJsonString(firstElement);
44
-
45
-
46
- Map<String, Object> result = (Map<String, Object>) UIQueryUtils.evaluateSyncInMainThread(new Callable() {
47
- @Override
48
- public Object call() throws Exception {
49
- return QueryHelper.executeAsyncJavascriptInWebviews(webView, "set_text.js", firstElementJson, args[2]);
50
- }
51
- });
52
-
53
- if (result.containsKey("error")) {
54
- return Result.failedResult(result.get("details").toString());
55
- }
56
- return new Result(true);
57
- }
58
-
59
- @Override
60
- public String key() {
61
- return "set_text";
62
- }
63
-
64
- }