This Tutorial Explains the Step-by-Step Process to Automate Web Applications on the Chrome Browser in an Android device with Screenshots and Examples:
To automate a Web Application on Android device, follow the steps listed below:
- Connect the mobile device or Create an Emulator
- Get details of the mobile device
- ChromeDriver Setup
- Start Appium Server
- Write Appium test script
- Interact with elements
- Run the script and automate the app
=> Check Here To See A-Z Of Appium Training Tutorials Here.
Table of Contents:
Automate Web App On Browser In Android Device
Here is a Video Tutorial:
Steps To Automate A Web App
#1) Connect The Mobile Device Or Create An Emulator
- Connect the real-time mobile device using a USB cable or create a virtual device in the system.
(Note: To create an emulator of a device, you can use AVD manager from Android SDK bundle or GenyMotion software)
- Now open a command prompt and run this command: adb devices
- Once you run this command, the device name will be listed in the response as shown in the image (if you get a response such as “daemon not running. daemon started successfully”, then try to run the command again).
- Note down the device ID. From the above example, the device Id/Name is AVY9KA9632202030.
#2) Get Details Of The Mobile Device
- In your mobile device, go to Settings>About Phone.
- Note the Android Version of the device as displayed below.
#3) ChromeDriver Setup
Like Selenium, Appium also interacts with the Chrome browser using Chromedriver. Hence, you need to setup Chromedriver as well. Download it from here and retrieve chromedriver.exe from the zipped file.
Place the chromedriver.exe file in the Appium folder path as below:
appium>node_modules>appium-chromedriver>win
#4) Start Appium Server
- Open Appium Desktop in the system. It might take a while to open.
- Once Appium Desktop opens, click on the Settings Tab.
- Note down the server address and port number.
- Click on the Play button to start the Appium Server.
- Once the server is launched, you will get a success message saying ‘Welcome to Appium….’
#5) Write Appium Test Script
- Set the initial configuration to start the Appium session.
Desired Capabilities, Properties of Device and Browser are defined.
RemoteWebDriver driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), cap);
An object of RemoteWebDriver is initiated because the automation is to be run on a remote device, not on the local computer.
URL of Appium Server is passed along with the Device and Browser details.
At runtime, the driver is initiated and Appium is connected using the Server address (http://127.0.0.1:4723/wd/hub). Also, all other device details are read from capabilities (cap) with which Appium will make a connection for automation.
The Web application is invoked using the driver.get() by passing the URL.
For Example, driver.get(“https://www.amazon.com”)
public class Amazon { WebDriver driver; DesiredCapabilities cap = new DesiredCapabilities(); @BeforeClass public void init() throws MalformedURLException{ cap.setCapability("deviceName", "AVY9KA9632202030"); cap.setCapability("platformName", "Android"); cap.setCapability(CapabilityType.BROWSER_NAME, "Chrome"); cap.setCapability(CapabilityType.VERSION, "5.1"); } @Test public void testApp() { driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); driver.get("https://www.amazon.com"); } }
#6) Interact With Elements
Inspecting elements on the browser in the Mobile devices is different from doing it on Desktop. Never use the same identification that we use for the desktop web app since the application structure differs from how it is displayed on desktop and mobile devices.
We have lots of applications available in PlayStore to inspect elements in a mobile browser.
- The highly recommended app to inspect elements in a mobile browser is ‘Inspect and Edit HTML live’. Install this in your Mobile device.
- Once installed, open the application, and hit the URL of the website you are trying to automate. (example – www.amazon.com)
- Once the application is open, you are free to inspect any element on the web app using the finger icon on the right corner.
- Click on the hand icon and then click on any element you need to identify.
- Once you click on an element in the application, its HTML tag is displayed with its attributes.
Using these, the element can be identified and used for further automation actions.
For Example, In the above example, I have attributes like class, name, id, etc. I can select the ‘Id’ attribute as an identification technique and recognize the element using XPath as:
//input[contains(@id,’search-keywords’)]
For Example,
@Test public void testApp() { driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap); driver.get("https://www.amazon.com"); WebElement SearchBox = driver.findElement(By.xpath(“//input[contains(@id,’search-keywords’)]”)); SearchBox.sendKeys(“mobile”); }
#7) Run The Script And Automate The App
- Run the script from eclipse.
- As the execution begins on the mobile device, Appium populates log for all the activities performed as below:
The log holds details of every activity like:
- Locating the chromedriver from local.
- Starting the chromedriver.
- Recognizing the device and establishing a session with it.
- Executing the actions in the script.
Conclusion
In this tutorial, we have seen the Step-by-Step Process to Automate Web Applications on the Chrome Browser in an Android device with Screenshots and Examples.
Appium can be used for automating any application on the mobile device by establishing a session with the device and interacting with elements on the application.
Suggested reading =>> How to disable Google Chrome Software Reporter Tool
PREV Tutorial | FIRST Tutorial
This is a nice step-by-step guide. I tried to follow it. However, I don’t find chromedriver and win folders inside appium-chromedriver folder. Do I have to create these folders manually? Can I keep the chromedriver just inside the node_modules? Second, I have been seeing this issue very persistent. The error is “java.lang.IllegalArgumentException: Unknown HttpClient factory netty”. Is this something you can help me with? I am willing to pay for your help. But I need help on this. Please respond to this request. Thank you.