Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Using Selenic with Appium

benken_parasoft Posts: 1,253 ✭✭✭

I am happy to share some tips about using Parasoft Selenic with Appium tests for mobile web apps.

First, let's look at how to record actions that Selenic can use to automatically generate an Appium test. The Parasoft Recorder extension for the Chrome desktop browser can be used to record actions against a mobile web app. Chrome must first be switched into a special mode to simulate a mobile device. To do this, open Chrome Dev Tools, click the "Toggle Device Toolbar" button then select your desired type of mobile device. Now, click the Start Recording button in the Parasoft Recorder then simply navigate to your mobile web app to begin recording the desired actions. When finished, click the Stop Recording button in the Parasoft Recorder then save your recording file to disk.

Next, the recording can be provided to Selenic to generate an Appium test. To do this, open Selenic (IDE plugin) then select "File > New > Selenium Java Project from Recording". Provide Selenic with the path to your recording and other requested information then click Finish. The project is setup and ready to use for Appium except for two things. :) We need to add Appium java client libraries to the project's build path and then need to reconfigure the test to connect to the desired Appium server.

The new java project has the Selenium java library and dependencies added to the project's build path. Now, we just need to add the java libraries for the Appium Java client. I was able to do this by downloading these extra jars then adding them to the project's build path (right-click project > Properties > Java Build Path):

After updating the build path we need to reconfigure the test to connect to an Appium server. In the main test class, locate the block of code that is instantiating ChromeDriver. It should look something like this:

driver = new ChromeDriver();

To use an Appium server, we need to change this code to instead instantiate the AndroidDriver or IOSDriver from the Appium java client, passing in the capabilities expected by the Appium server. For example, this is what I used to connect to an Appium server on my local machine for playback in Chrome on an emulated Android device:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("w3c", false);
driver = new AndroidDriver<>(new URL(""), capabilities);

The capabilities being configured depends on what Appium server is being used and what mobile device and mobile browser will be used to execute the steps in the test. The Appium docs describe the capabilities that are available. However, if you are not using your own Appium server and are instead needing to connect to a mobile device (cloud) provider, then the capabilities often need to be setup in a way that is very specific to that provider.

Once you have your Appium test you can run it with Selenic no different than any other Selenium Test. Selenic can generate recommendations, heal bad locators, etc. no different than if the test were being executed using a desktop browser.