Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Silk WebDriver to Test on Mobile

DZone's Guide to

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.

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

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.

Setup

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.

setup downloading

Silk WebDriver setup extracting

Silk WebDriver, select installation location

At the end of the setup, you can start Silk WebDriver straight away by just clicking on Done.

Final page of Silk WebDriver setup

Getting Started

When you start Silk WebDriver for the first time, it will initially look like this:

First-time start of Silk WebDriver

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:

Main window of Silk WebDriver

If you click on "Record new script," you can select the desktop browser you wish to record in, e.g. Google Chrome.

Select browser dialog of Silk WebDriver

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.

Navigate to nasdaq.com

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:"

Image title

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:

Selecting the verification 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.

Replaying the test script on Windows

Now you can save your script. Either use the CTRL + S shortcut or select Save from the menu at the top right:

Save your test script

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.

Configure devices

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

Select your Android device

At this stage you will be invited to start the thirty-day trial to access the mobile feature:

Start your trial

Once you have done that you will see a dialog indicating Silk WebDriver is connecting to the mobile device:

Connecting to mobile device

This takes a moment and when it is finished you can replay the script you just recorded on the mobile device.

Script replaying on the mobile device

In this case, the script fails because there is no "Contact" link on the mobile version of the web app:

Test fails because there is no contact link

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:

Record on mobile

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:

Mobile screen loading

After that, you can record actions on mobile and then replay them on Windows in the same way as described above.

Conclusion

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.

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
devops ,webdriver ,mobile testing ,selenium ,functional testing ,test automation

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}