Parallel Execution in Appium using TestNG


You should have knowledge on TestNG and use of it.
Note : Node.js should be installed on the machine.


Setup first device: 

Open command prompt, appium and open device or emulator
Go to Command prompt and change the location to cd C:\Program Files (x86)\Appium\node_modules\appium\bin
 Next enter below command on command prompt
 " node appium.js -a 127.0.0.1 -p 1234 -cp 1234 -bp 2345"
Here 127.0.0.1 is your Appium server address and 1234 your port number.

Note: You can change according to your appium server address.

How you will get to know about the Appium server address?
Ans:
Go to Appium setting option, you will find server address and port address.

Setup Second Device:

Open another command prompt,appium  and open another device or emulator
Again Go to Command prompt and change the location to cd C:\Program Files (x86)\Appium\node_modules\appium\bin
now enter below command on command prompt
node appium.js -a 127.0.0.3 -p 2346 -cp 2346 -bp 3456
Make sure that both command prompts are running different instance of appium .

Before that make sure both devices should get connected . Run the command "adb devices" on command prompt and note both id of devices and set capabilities while writing program.

Here 127.0.0.3 is your Appium server address and 2346 your port number.

Note: You can change according to your appium server address.
Below Example:
We can use parameterise concept of TestNG .Same way  we will create testng.xml how we  are creating for  selenium parallel execution.

Note :

-p the main Appium port
-U the device id
-bp the Appium bootstrap port
--cp the chromedriver-port(if using webviews or chrome)
-- sp selendroid-port the selendroid port (if using selendroid)
If we had two devices with the ID’s 3445 and 6574, we would start two different Appium servers with the following commands:
node . -p 4342 -bp 3251 -U 3445
node . -p 4344 -bp 3252 -U 6574


4724 is default bootstrap port

testng.xml


<suite name="Suite" parallel="tests" thread-count="2" >
<test name="Test1">
<parameter name="deviceName" value="FirstDevice"/>
<parameter name="UDID" value="UDID1"/>
<parameter name="platformVersion" value="Version1"/>
<parameter name="URL" value="127.0.0.1:1234/wd/hub"/>
<classes>
<class name="appium_automation.ParallelDeviceSetup"/>
</classes>
</test> <!—Test 1 -->
<test name="Test2">
<parameter name="deviceName" value="second device"/>
<parameter name="UDID" value="UDID2"/>
<parameter name="platformVersion" value="Version2"/>
<parameter name="URL" value="127.0.0.3:2346/wd/hub"/>
<classes>
<class name="appium_automation.ParallelDeviceSetup"/>
</classes>
</test> <!—Test 2 -->
</suite> <!-- Suite -->
                         



public class ParallelDeviceSetup {
AndroidDriver<AndroidElement> driver;

@Test
public void f() {
}

@Parameters({ "deviceName","UDID","platformVersion", "URL" })
@BeforeMethod
public void beforeMethod(String deviceName,String UDID,String platformVersion,String URL) throws MalformedURLException, InterruptedException {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/Apps/BigBasket/");
File app = new File(appDir, "bigbasket_com.bigbasket.mobileapp.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", deviceName);
capabilities.setCapability("udid", UDID);
capabilities.setCapability("platformVersion", platformVersion);
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.bigbasket.mobileapp");
capabilities.setCapability("appActivity", "com.bigbasket.mobileapp.activity.SplashActivity");
driver = new AndroidDriver<AndroidElement>(new Uri(ConfigurationManager.AppSettings["URL"]), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
}

@AfterMethod
public void afterMethod() {
}
}

No comments:

Post a Comment

Copyright © 2017 QALEARNINGGUIDE.COM || ALL RIGHTS RESERVED