Skip to content
Tobias Røikjer edited this page Aug 16, 2014 · 10 revisions

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:

  1. 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.

  1. 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:'*'")

Touching

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'")

Entering text

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'", "ruk")

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.

Cordova Web Views

Note that when using cordova android platform or cordova webviews you must instead specify cordovaWebView, like so:

query("cordovaWebView css:'#header'")
query("cordovaWebView css:'.js-current-repository'")
query("cordovaWebView css:'a'")

If you don't specify cordovaWebView your calabash test will completely fail to recognise webview and you'll probably cry.

Clone this wiki locally