Using Silk WebDriver to Test on Mobile
Using Silk WebDriver to Test on Mobile
Silk WebDriver allows you to record Selenium WebDriver scripts. Learn how to use it for testing web applications on a mobile device.
Join the DZone community and get the full member experience.Join For Free
As a web app developer, you want to be sure the software you develop runs as intended and looks well on all end-user devices. In earlier years you could be confident that most users were on desktop computers running OSes like Microsoft Windows. Nowadays, more and more end users are on mobile platforms like Android and iOS. It can be quite a challenge to test on all platforms. To ease this testing challenge, in addition to desktop browsers, Silk WebDriver provides support for recording and replaying Selenium WebDriver UI tests on mobile devices. This means you can, for example, record a test on Windows, and replay it on Android (or the other way round).
Silk WebDriver is a new app released in 2017 specifically for recording Selenium WebDriver scripts (see my earlier article). There are three versions which provide increasing levels of functionality: free non-registered, free registered, and pro (you can try out the pro version with a 30 day trial). The ability to test on mobile devices is a feature of the pro version. This tutorial intends to walk you through just how to do that from initial download through to replaying (and recording) tests on mobile.
At the time of writing this article, you can download the Windows setup only. Download Silk WebDriver from here.
Run the Setup executable and the installation files will be extracted. Choose the folder where you want to install Silk WebDriver (or leave the default) and click Install.
At the end of the setup, you can start Silk WebDriver straight away by just clicking on Done.
When you start Silk WebDriver for the first time, it will initially look like this:
If you just want to start using Silk WebDriver straight away, at the bottom of the dialog, you can click on "Not now, maybe later" instead of signing up. Later, when you want to use the mobile feature, you will be invited to start a thirty-day trial.
The main window of Silk WebDriver looks like this:
If you click on "Record new script," you can select the desktop browser you wish to record in, e.g. Google Chrome.
Enter the URL of your web app you wish to test. For this tutorial, we will use a website/web app created with AngularJS, which I found on https://www.madewithangular.com. You can also see the URL of the site we will use in the following screenshot.
Recording on Windows
Let's say this is your company's web app and you record a test on Chrome on Windows 7. When you click on OK, a sidebar opens on the right where you see the actions which you record. The test could be something like "Go to the contact page and verify the heading:"
Note that verifications can be added by using the shortcut CTRL + ALT or else by right-clicking and selecting the verification button from the dialog:
You can replay your test directly in the Silk WebDriver sidebar to make sure it works ok. Do this by selecting the 'Recorded Actions' line and then clicking on the play button at the bottom of the sidebar.
Now you can save your script. Either use the CTRL + S shortcut or select Save from the menu at the top right:
Replaying on Mobile
After that, you want to know if the test also works properly on mobile. For example, when you make changes to the app you want to ensure you have not broken anything on the mobile platform. You can do this by selecting Configure Devices from the menu at the top left.
In this case, we want to select an Android 6.0 device. Ensure your Android device is connected and is visible via ADB (for troubleshooting, see the Silk WebDriver help).
At this stage you will be invited to start the thirty-day trial to access the mobile feature:
Once you have done that you will see a dialog indicating Silk WebDriver is connecting to the mobile device:
This takes a moment and when it is finished you can replay the script you just recorded on the mobile device.
In this case, the script fails because there is no "Contact" link on the mobile version of the web app:
The failure is indicated by the red icon (containing an exclamation mark) to the right of the action which failed.
Recording on Mobile
Another scenario you might want is to record a test initially on mobile and then try it out on desktop:
Silk WebDriver will display the mobile screen in a window on your desktop as you can see from the following screenshot taken while the app was navigating to the URL:
After that, you can record actions on mobile and then replay them on Windows in the same way as described above.
In summary, the mobile feature of Silk WebDriver Pro gives you the ability to quickly check if a desktop test runs on mobile and vice versa. This can be very useful for ensuring your software works across as many end-user devices as possible. Obviously, when you have exported your test script to your favorite programming language you will want to schedule it in your nightly CI build.
Opinions expressed by DZone contributors are their own.