Mobile app developers use WebViews to embed HTML web content into native mobile apps. Mabl offers two options for training against elements in WebViews:
This article explains how to test WebViews in the mabl Trainer.
Default settings
Most WebViews can be tested without any additional configuration. By default, when you interact with and assert on elements, the Trainer automatically converts most WebView elements into native mobile elements.
Training against native elements is usually faster than training against WebView elements.
However, if it is difficult to target the correct WebView element, consider enabling advanced WebView support. With Advanced WebView support you can interact with WebViews in a similar way to mabl's browser testing.
Advanced WebView support
Enabling advanced WebView support is helpful in the following situations:
- The Trainer fails to identify the correct WebView element when you use the default settings.
- You want to assert on specific browser attributes.
To train against a mobile build with advanced WebView support, take the following steps:
- Confirm that the mobile build file has debuggable WebViews
- Enable advanced WebView support
- Train your test
Note: if you are working with a hybrid application that is primarily built with web technologies, we recommend using advanced WebView support for an optimal experience.
Confirm that the mobile build file has debuggable WebViews
Before you enable advanced WebView support, confirm that the WebViews in your mobile build file are debuggable and can execute JavaScript:
-
iOS: each WebView must be marked as inspectable. For example, if
#available(iOS 16.4,*) {webView.isInspectable = true}
. Learn more. -
Android: Enable WebView debugging mode by calling the
setWebContentsDebuggingEnabled(true)
method on theWebView
class. Learn more. thejavaScriptEnabled
flag for each WebView must be set totrue
. Learn more.
If you do not have a debuggable mobile build, make the necessary code changes, export a new version of the build file, and upload it to mabl for training.
Enable advanced WebView support
After you upload the build file to mabl, enable advanced Webview Support:
1. Go to mabl > Settings > Preferences
2. Click on the Mobile tab
3. Check the box for “Enable advanced WebView support”
Train your test
Create a new mobile test using the newly uploaded debuggable build file. When you tap on elements in a WebView, the Trainer automatically detects that the elements are in a WebView and adds a “WebView” tag to the step.
Step with a WebView tag
For Android builds, the first time you interact with a WebView on the page, mabl downloads Chrome Driver to your local machine.
If you do not make the required code changes to test inside WebViews, the mabl Trainer attempts to interact with the WebView and can time out with the message “Unable to test WebView.”
When you assert on an element that exists in a WebView, you have two options:
Option | Details |
Select a native element |
|
Select a WebView element |
|
Asserting on native elements is usually faster than asserting on WebView elements. However, if the native element assert fails to identify the correct element, or if you want to assert on specific browser attributes, assert the WebView element.
Asserting on a WebView element
To illustrate the difference between asserting on a native element and asserting on a WebView element, consider the two assertions on the same element shown in the following screenshot. Step 5 asserts on the native element "continuous testing", whereas step 6 asserts on the WebView element "continuous testing" and captures details about the link:
Asserting a native element vs. asserting a WebView element
The following steps are currently supported for advanced WebView interactions:
- Tap steps
- Assertions
The following interactions are not currently supported:
- Configure Find
- Scrolls
- Enter text
- Conditionals
- Extract element attributes to a variable