Experitest Blog

Comparing and combining web and mobile test automation drivers

There are a number of tools used for web and mobile test automation. They vary in functionality, supported platforms and terms of use. For this purpose, we will only concentrate on two of them: Appium and Selenium.

 

Developers and testers use the Appium framework for the automation of web, native and hybrid mobile applications. The Selenium framework is used for web application automation. Additionally, Selenium is written in JAVA, Appium – in JavaScript. Although at the first glance they are different, they have one common thing: Appium and Selenium use the webDriver protocol to communicate with the target platform: Appium with the mobile device, Selenium with a web browser correspondingly. Generally, a Selenium webDriver script is executable in both a mobile device browser and in a desktop browser to exercise the same actions against the same web application.

 

The difference between web and mobile test automation drivers

 

Above all the difference between web and mobile test automation drivers lies in the functionality, supported platforms and the configuration of the test bench to run tests. Appium, in particular, acts as an HTTP server for which there are several clients: Java, JavaScript, Python, C#, Ruby. In fact, an Appium client is the wrap over the Selenium webDriver client libraries. Appium, in addition to Selenium, uses an extended set of the webDriver APIs, specific for the interaction with mobile devices. For example, Appium includes commands to support multi-touch gestures and screen orientation, to manage geolocation data, to access device logs and many others.

 

The Appium server gives access to Appium users to control functions of the device under the test, such as installation and removal of an application during the test session. The same client implementations exist for Selenium. But a Selenium server is required for distributed test execution only if we need to install Selenium grid.

 

To clarify, Selenium supports major browsers running in the main desktop operating systems. Appium supports a large variety of iOS and Android devices, for the officially supported versions of iOS and Android. In addition, Appium can provide the automation of MS Windows applications. On the other hand, there is a difference in efforts, which are required to configure the infrastructure for Appium and Selenium testing. To conduct Appium testing you need to install nodeJS, install Appium, configure SDK and specific device drivers and frameworks. For a Selenium testing case, there are not so many steps to configure the environment for tests developments and execution, unless you install the Selenium server to run tests against Selenium Grid. Appium and Selenium stacks diagram are shown on the pictures below.

 

 

The example of using both frameworks for mobile web automation

 

The common basis in both frameworks makes it possible to use them together for web and mobile test automation, despite the differences listed above. When we need to test a web application in the mobile browser, we can use both Appium and Selenium frameworks and they will complement each other in one test. Below you will see a simple test, for example, which opens a page of the Amazon.com site in the Android Chrome browser on a mobile device.

 

package tests.web;

import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileBrowserType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
public class AndroidWebTest {
   private static final String ACCESS_KEY = System.getenv(“SEETEST_IO_ACCESS_KEY”);
   private static final String CLOUD_URL = “https://cloud.seetest.io:443/wd/hub”;
   private static final String TITLE = “Testing Website on Android Chrome with Java”;
   private AndroidDriver driver = null;

   @Before
   public void setUp() throws MalformedURLException {
       DesiredCapabilities dc = new DesiredCapabilities();
       dc.setCapability(“testName”, TITLE);
       dc.setCapability(“accessKey”, ACCESS_KEY);
       dc.setBrowserName(MobileBrowserType.CHROME);
       driver = new AndroidDriver(new URL(CLOUD_URL), dc);
   }

   @Test
   public void testAppiumOnChrome() {
       driver.get(“https://amazon.com”);
       System.out.println(driver.getTitle());
       if (driver.getCapabilities().getCapability(“device.category”).equals(“TABLET”)) {
           driver.findElement(By.xpath(“//*[@name=’field-keywords’]”)).sendKeys(“iPhone”);
           driver.findElement(By.xpath(“//*[@text=’Go’]”)).click();
       } else {
           driver.findElement(By.xpath(“//*[@name=’k’]”)).sendKeys(“iPhone”);
           driver.findElement(By.xpath(“//*[@value=’Go’]”)).click();
       }
   }

   @After
   public void tearDown() {
       if (driver != null) {
           driver.quit();
       }
   }
}

 

Test codes use both Selenium and Appium libraries to interact with the browser on a mobile device. Appium client objects are used to initialize a device driver, define the Android Chrome browser and control it. Selenium is used to define “Desired capabilities” object, which controls the device driver, mobile browser and interacts with the web application (in the test, the Amazon.com website is used), by means of the Selenium object “By”. Using these objects gives access to the web elements of the mobile browser.

 

The test is executed on the SeeTest platform – cloud-based platform, offering a great number of browsers and mobile devices for development and web and mobile test automation. For comparison, there is the test, that opens cloud.seetest.io website page in the Google Chrome browser on the Mac platform, then finds a few links on the page and clicks on the links found. In this case, only Selenium objects are used, which control the remote browser on the SeeTest cloud platform and perform actions specified in the test.

 

package tests.web;

import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ChromeTest {
   private static final String ACCESS_KEY = System.getenv(“SEETEST_IO_ACCESS_KEY”);
   private static final String CLOUD_URL = “https://cloud.seetest.io/wd/hub/”;
   private static final String TITLE = “Selenium Test on Chrome”;
   private RemoteWebDriver driver;

   @Before
   public void setUp() throws Exception {
       DesiredCapabilities dc = new DesiredCapabilities();
       dc.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
       dc.setCapability(“accessKey”, ACCESS_KEY);
       dc.setCapability(“generateReport”, true);
       dc.setCapability(“testName”, TITLE);
       driver = new RemoteWebDriver(new URL(CLOUD_URL), dc);
   }

   @Test
   public void testSeleniumOnChrome() {
       driver.get(“https://seetest.io”);
       System.out.println(driver.getTitle());

       new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath(“//*[text()=’Manual’]”)));

 

       WebElement manualNavLink = driver.findElement(By.xpath(“//*[text()=’Manual’]”));
       manualNavLink.click();
       WebElement automationNavLink = driver.findElement(By.xpath(“//*[text()=’Automation’]”));
       automationNavLink.click();
       WebElement webinarFooterLink = driver.findElement(By.xpath(“//*[text()=’Webinars’]”));
       webinarFooterLink.click();

 

       String webinarH2TitleText = driver.findElement(By.xpath(“//h2[1]”)).getText();
       System.out.println(“The title of the first h2 is: ” + webinarH2TitleText);
   }

   @After
   public void tearDown() {
       if (driver != null) {
           driver.quit();
       }
   }
}

 

The second test is also executed on the SeeTest platform and is ready to be run. Both tests can be downloaded, compiled and launched. Use ‘mvn clean install’ command for it. As both tests are supposed to be executed on the SeeTest platform, don’t forget to add the access key from your SeeTest account to the system variables, before you launch tests.

The first example shown above illustrates both Appium and Selenium testing and is one of the examples of the web and mobile test automation. This case happens when a web application is required to be run in both the desktop and mobile browsers, which often happens nowadays.

 

An example of using Appium and Selenium for automation of native mobile applications

 

Besides a requirement to support various browsers on multiple mobile and desktop platforms, modern applications may have multiple types of client: web, desktop, mobile, which in turn can be run on diverse hardware platforms under various operating systems. For a QA engineer, above all, it means the necessity to conduct tests on all possible combinations of hardware, OS, and browser. For instance, a possible use case, when two different clients are used, is the case when a user from the mobile client performs some action and another user from the web client gets the result of this action or vice versa.

 

The example of such a case is a post in a social network which has to be checked by different clients. Another example is a chat, where a user from a mobile client sends a message and a user from a web client receives the message or vice versa. From the test case perspective, it will have to imitate the interaction between the two types of clients: mobile and web client. So in one test both Appium and Selenium frameworks will be used and this type of tests combines both Selenium and Appium testing. In this test, Appium objects are used to manage the mobile device, while Selenium objects are used to manage and interact with the browser on the desktop platform. A test is also supposed to be executed on the SeeTest cloud service.

 

As for implementations, tests for these clients can be written in separate modules and executed in parallel using SeeTest for the corresponding instances. In this example, Selenium and Appium complement each other. This is another example of web and mobile test automation.

 

Is the Appium framework based on Selenium or not?

 

And finally here’s a note about automation of native mobile applications. When we write UI tests for them and interact with the elements on mobile pages, we access them through the object which is an instance of the class io.appium.java_client.MobileElement extended from the org.openqa.selenium.remote.RemoteWebElement. This means, that tests for the native mobile applications will use Selenium implicitly to access mobile pages elements.

 

Conclusion

 

To sum up, Selenium and Appium are not isolated frameworks, which can be used only for web and mobile test automation correspondingly, these frameworks can be used together in one test for testing web applications in the mobile browser and for the implementation of complex test cases, which involve interactions with web and mobile clients. All these test cases can be easily executed on the SeeTest platform, which in short provides a variety of mobile devices and browsers for tests. Furthermore, SeeTest is ranked at the top among cloud platforms for conducting web and mobile test automation.

 

automation drivers

Konstantine FirsanovHead of QA at ISS Art Team

 

Comments are closed.