-
Notifications
You must be signed in to change notification settings - Fork 617
06 webview support
Calabash Android supports querying and acting on webview content.
To look into a webview you simply use the query function and syntax. The syntax for webviews is a bit irregular (and we will clean this up at some point), but there is quite good support.
Here are some examples:
-
Query for an element with id, class or tagname
query("webView css:'#header'") query("webView css:'.js-current-repository'") query("webView css:'a'")
The string after css: can be any css selector.
-
Get all the HTML associated with the webview:
query("webView css:'*'")
Note query will only return DOM nodes that are visible on the screeen! (They should be visible and their center should be within the webview viewport). You can, as with any other queries, disable visibility filtering by adding 'all' at the start of your query string. query("all webView css:'*'")
As usual, anything you can query, you can touch (but the element must be visible to be found).
query("webView css:'a'").first
touch("webView css:'a'")
You can use the enter_text
method to enter text in a webview (in addition to any other android widget).
enter_text("webView css:'input.login'", "run")
This will enter the text "run" into the first input field of the class 'login'.
If the input field already has focus, you can use keyboard_enter_text(text)
to append the text.
Note that when using cordova android platform or cordova webviews you must instead specify cordovaWebView or SystemWebView, like so:
query("cordovaWebView css:'#header'")
query("cordovaWebView css:'.js-current-repository'")
query("cordovaWebView css:'a'")
query("SystemWebView css:'#header'")
query("SystemWebView css:'.js-current-repository'")
query("SystemWebView css:'a'")
If you don't specify cordovaWebView or SystemWebView your calabash test will completely fail to recognize the webview and you'll probably cry.
Similar to Cordova, when using react native, you need to specify reactWebView
instead of webView
like so
query("reactWebView css:'#header'")
query("reactWebView css:'.js-current-repository'")
query("reactWebView css:'a'")
When an alert is displayed (via the window.alert()
method), you can confirm its appearance on screen with
Then I wait to see "The alert text"
and you can dismiss it with
Then I press "OK"