Handling HTML inside Android WebView in Testdroid Recorder!

Bitbar, the mobile devops company. Logo, large

Hi all,
we are very proud to introduce you new way of testing WebView in your applications. Especially to record and playback tests for html-based application embedded in WebView (for instance by using PhoneGap framework).
We extended our recorder-extensions library using by playback tests and we implemented recognition of actions on HTML elements inside WebView in the newest version of Testdroid Recorder.

Recording from WebView
Now we are recording following commands on HTML elements in WebView:

  • clickOnHtmlElement(String tag, String id, String name, String class, int index)
  • enterTextIntoHtmlElement(String tag, String id, String name, String class, String text, int index)
  • waitForHtmlElement(String tag, String id, String name, String class, int index, int time)
  • htmlGoBack()
  • htmlGoForward()
  • htmlZoomIn()
  • htmlZoomOut()

In addition you can easily add following asserts using append command during recording:

  • elementExistsOnHtmlPage(String tag, String id, String name, String class, int index)
  • isTextPresentOnHtmlPage(String text)

We also provide one additional auxiliary method to get whole html from WebView:

  • getHtmlCode()

As you can see in commands above, we are recognizing HTML elements on five parameters. Tag is obligatory, rest are optional. Tag, id, name, class are HTML attributes, index is our parameter. There can be few elements with the same attributes, so we are indexing them.

Possibilities and limitations
We are able to record and playback actions on WebView, if you fulfill a few limitations.

  • Firstly your WebView has to have WebViewClient set for WebView.
  • Then you can’t filter loading urls in method shouldOverrideUrlLoading to prevent loading urls with “javascript:” prefix.
  • Finally now we support pure HTML and JavaScript applications and also jQuery and jQuery Mobile frameworks. If you based on another framework in your application we may not handle them. Anyway we are waiting for feedbacks and we are ready to extending our solution for other frameworks which may be important for our customers in the future.

Recording actions from WebView requires to load the script inside the page. This may take some time, so please be patient, if the actions are not recorded. Same playing tests need to load scripts and create an appropriate interface between the WebView and Eclipse. Therefore, playing tests may take a little longer than they were recorded.

We have prepared simple demo usage of Testdroid Recorder to record actions from WebView. Enjoy: