Introduction Appium Simple Web test creation and execution Executing the Test Prerequisites Start Appium Server Create Run Configuration in IntelliJ Execute the Run Configuration
Introduction
With the advent of Smartphones, Enterprises have to cater their applications to Mobile devices in addition to web testing for desktop Computers.
Typically, Native applications are built for Mobile devices, but this is not enough. The reason is there are Customers who do not wish to install native applications due to reasons like,
- Space restrictions.
- A quick review of the product does not require installation of Native applications.
- Avoid Native application notification affecting the speed of the mobile device.
Hence it is important that Web Applications which are lighter and require no additional installations to be also receptive to Mobile browsers. This also means that the testing now requires for supportability of these applications in Mobile browsers. Android
This article focuses on Web Testing on Mobile devices using the Android Operating System
There are several tools available which support Web Testing in Android and few of them are,
- Appium
- Selendroid
- Espresso Web
- Robitium
Appium
The table below summarizes how Appium compares with other tools on Automation testing.
[table id=61 /]
We can see that Appium has more advantages than its peers with broader language support, larger developer community, and cross-platform being important ones.
The rest of the article will focus on a short tutorial on how to develop a simple Web test in Appium.
Simple Web test creation and execution
Creating the Web Test using Appium
We will use Java as a programming language and IntelliJ IDE in these instructions.
Step 1. Create a Gradle Project in IntelliJ
Specify the name of the Gradle project.
In the rest of the screens, choose defaults and click next and in the final step finish to create the project.
Step 2. Specify the dependencies in build.gradle file.
Open the build.gradle file and replace existing ‘dependencies’ directives following lines.
[java] dependencies { compile group: ‘org.testng’, name: ‘testng’, version: ‘+’ compile group: ‘io.appium’, name: ‘java-client’, version: ‘+’ } [/java]
Save the project and click ‘Import changes’ alert popped up by IntelliJ.
This will download all the dependencies.
Step 3. Create a Java file and Implement the Test.
Select the project’s Java folder and create the Java class named AppiumWebTest.
Now we start creating the Test using the TestNG framework, below are important.
Initializing the driver
Appium requires the initializing of WebDriver to connect the Appium Server/Devices. In general, initialization needs to be accomplished by passing the Desired capabilities. Desired capabilities define session attributes. Typically these form the initialization for the Test class and need to be in the initialization function of the Test framework.
Note: deviceName can be found out by executing command ADB devices. More information on this can be found in Enabling Developer Mode.
[java] DesiredCapabilities dc = new DesiredCapabilities(); protected RemoteWebDriver driver = null; . . dc.setCapability(“platformName”,”Android”); dc.setCapability(“deviceName”, DEVICE_NAME); dc.setCapability(, “Chrome”); dc.setCapability(“chromedriverExecutable”,”CHROME_DRIVER_PATH”); driver = new AndroidDriver(new URL(APPIUM_SRV_URL), dc); [/java]
In the above capabilities, browserName and chromedriverExecutable are specifically used in Web Testing context.
[table id=62 /]
Note: In order to automate any browser, Appium needs a browser driver. Please refer to the documentation Appium automating of mobile web apps.
Test Method
Test function in the context of Mobile Web testing involved primarily, loading the Web application, locating the UI elements, and executing the automation commands.
[java] @Test public void testWeb() { // loading web url driver.get(“http://www.google.com”); // locating element. By qBy = By.xpath(“//*[@name=’q’]”); // click and sendkeys automation commands driver.findElement(qBy).click(); driver.findElement(qBy).sendKeys(“experitest”); driver.findElement(qBy).sendKeys(Keys.ENTER); } [/java]
Releasing the driver
[java] @AfterTest public void tearDown() throws MalformedURLException { driver.quit(); } [/java]
The final test will look like this,
[java] import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; import io.appium.java_client.remote.MobileCapabilityType; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; /** * Class for Web Testing using Appium in an Android Device. */ public class AppiumTest { DesiredCapabilities dc = new DesiredCapabilities(); protected RemoteWebDriver driver = null; public static final String APPIUM_SRV_URL = “http://localhost:4723/wd/hub”; public static final String DEVICE_NAME = “a3ae1c63”; public static final String CHROME_DRIVER_PATH = “C:\experitest1\chromedriver_win32\chromedriver.exe”; @BeforeTest public void setUp() throws MalformedURLException { dc.setCapability(“platformName”,”Android”); dc.setCapability(“deviceName”, DEVICE_NAME); dc.setCapability(“browserName”, “Chrome”); dc.setCapability(“chromedriverExecutable”,”CHROME_DRIVER_PATH”); driver = new AndroidDriver(new URL(APPIUM_SRV_URL), dc); } @Test public void testWeb() { driver.get(“http://www.google.com”); By qBy = By.xpath(“//*[@name=’q’]”); driver.findElement(qBy).click(); driver.findElement(qBy).sendKeys(“experitest”); driver.findElement(qBy).sendKeys(Keys.ENTER); } @AfterTest public void tearDown() throws MalformedURLException { driver.quit(); } } [/java]
The example project associated with this blog is located at First Web Test using Appium.
Executing Web Testing
- The latest version of Java, needed for Android Studio.
- Installation of Android Studio with SDK. This is needed since adb gets installed as part of the Android SDK. The adb utility is required to get the device list connected to the PC.
- Installation of the latest version of IntelliJ.
- Connecting the Mobile device to the PC using USB cable and enabling the developer mode/USB debugging in the android device.
- Installation of Appium Desktop.
Start the Appium Server by launching Appium Desktop and then clicking the Start Server button.
Create Run Configuration in IntelliJ
To create a Run Configuration file navigate to IntelliJ Menu > Run > Edit Configurations. This will open up a dialog box. Click on +, Specify a name in the ‘Name’ field. Select the class name in the Class field and Click OK to save.
Execute the test by executing the Run Configuration created above by navigating to Run > Run Configuration name (AppWebTestTestNG)
https://www.youtube.com/watch?v=0ByjNEuSP-E&t=2395s
Are you ready to scale your enterprise?
Explore
What's New In The World of Digital.ai
100% Test Automation Might Be Desirable, But Is It Practical?
Discover the challenges and value of test automation in achieving 100% coverage for continuous testing. Find the right balance for effective software development.
Digital.ai Continuous Testing, Now Supports Testing on iOS 17 (Beta) Devices
Digital.ai Continuous Testing is the first to support a new operating system version. iOS 17 (Beta) has been released – Discover the new features and see how it works with a demo below.
Ensuring Quality: Digital.ai Continuous Testing Honored with a DevOps Dozen Award
Digital.ai Continuous Testing wins Best Testing Service/Tool at the DevOps Dozen Awards 2022, recognizing their exceptional code quality assurance and innovation.