Oct 28, 2017

Run Appium tests with Selenium Grid & Node

Appium is an open source test automation tool for mobile applications and allows you to test all the three types of mobile applications: native, hybrid and mobile web on Android and iOS platforms.It also allows you to run the automated tests on actual devices, emulators and simulators.

Appium is Cross-Platform tool and allows the scripts to run on multiple platforms by using the same set of API. Appium is usually combined with Selenium for automated testing on mobile apps.


What is Selenium-Grid?


Selenium-Grid allows you run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems. Essentially, Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.

When to Use It?

  • To run your tests against multiple browsers, multiple versions of browser, and browsers running on different operating systems.
  • To reduce the time it takes for the test suite to complete a test pass.

Pre-Requisites : 


Selenium Grid - Hub SetUP : 


1. Open the command prompt and navigate to Selenium jar file location then run the below command to start a hub on your system
  • java -jar selenium-server-standalone-3.6.0 -role hub
2. The above command will run the selenium hub in your system ip address with the default port of 4444. You can see the below console once Hub is running successfully and up.





















Appium Node Configuration SetUp :


1. The configuration of Appium Node is usually maintained with Json configuration files as shown with the following details.

{
"capabilities": [
{
"browserName": "Chrome",
"version":"8.0",
"maxInstances": 3,
"platform":"ANDROID",
"deviceName":"Android Emulator"
}
],
"configuration":
{
"nodeTimeout":120,
"port":4723,
"hubPort":4444,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url":"http://192.168.0.20:4723/wd/hub",
"hub": "192.168.0.20:4444/grid/register",
"hubHost":"192.168.0.20",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":2000,
"timeout":30000,
"maxSession":1

}
}

2. Copy the above configuration into notepad and save on NodeConfig.json file.

3. Open the command prompt and navigate to .json file location then run the below command to register node with running hub on your system
  • appium -p 4723  --nodeconfig NodeConfig.json
4. The above command will run the appium server in 0.0.0.0 address with the port of 4723 and register with running hub on your system. You can see the below console once Node is successfully registered with Hub.






















Example :


To run appium scripts on your grid machine you have to pass the hub url in Appium driver instance creation and pass the mentioned capabilities in the node machine. Let us see the sample program to run appium test with grid configuration.


import java.net.MalformedURLException;
import java.net.URL;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class MobileBrowserTest {

DesiredCapabilities capabilities;
static AppiumDriver driver = null;

@BeforeSuite
public void setup() throws MalformedURLException{

capabilities = new DesiredCapabilities(); 
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability(CapabilityType.VERSION, "8.0"); 
capabilities.setCapability("platformName", "Android");

driver = new AndroidDriver(new URL("http://192.168.0.20:4444/wd/hub"), capabilities);

}

@Test
public void TC1(){


driver.get("https://www.google.co.in");
driver.findElement(By.name("q")).sendKeys("Welcome");

}

@AfterSuite
public void tearDown(){

if(driver!=null)
driver.quit();

}


}



No comments:

Post a Comment

Mobile App Automation with Appium on Android Emulator/Device

Overview :- Appium  is an open source test automation tool for mobile applications. It allows you to test all the three types of mobile...