0

I have a requirement in my project to run set of test cases in multiple devices in parallel. For example my testng xml is like below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
  <suite name="Automation" parallel="tests" thread-count="2">
    <test name="RegressionMobileTest_TC01">
        <parameter name="DeviceCapability" value="Android_6.0_Phone/>
        <classes>
            <class name="TestScenarios.WhatIf.TC01_VerifyLaunch" />
        </classes>
    </test> 
     <test name="RegressionMobileTest_TC011">
        <parameter name="DeviceCapability" value="Android_7.0_Tablet" />
        <classes>
            <class name="TestScenarios.TC01_VerifyLaunch" />
        </classes>
    </test>
</suite> 

I need to provide multiple device ID as value for

<parameter name="DeviceCapability" value="Android_6.0_Phone"/>

Like

<parameter name="DeviceCapability" value="Android_6.0_Phone, Android_6.0_Phone"/>

So that I can have parallel execution done in all the devices for all the classes mentioned in the test. How can I achieve the same in testng. Please suggest.

Thanks in advance.

  • How about using Selenium Grid? – Nael Marwan Dec 17 '18 at 06:56
  • Hi Nael, We have our framework to support testng suite and we are proceeding with the same. One more information, we are accessing device from cloud and so starting of multiple appium server is not required. It will be taken care at cloud level. Can you please help. – user7475997 Dec 18 '18 at 06:09
  • Got it. Let me ask you few questions first, are you trying to execute the same test multiple times on different devices? Or each test should be executed on one device only according to the parameter you pass? – Nael Marwan Dec 18 '18 at 06:37
  • Hi Nael, I want to execute same test case in multiple devices for single time. Which in turn gives me multiple runs for the same test case. Hope this clarifies. – user7475997 Dec 19 '18 at 05:34
  • Did implement the it? – Nael Marwan Dec 26 '18 at 15:09
  • Hi All, Thanks for all your response. We got parallel execution configured in CICD tool (BAMBOO) which works perfectly without modifying the TESTNG xml. – user7475997 Apr 02 '19 at 12:34

1 Answers1

0

You need to pass parameters by dataprovider instead of passing by testng.xml.

@DataProvider(name="DeviceCapabilityProvider", parallel = true)
    public Object[][] getDataFromDataprovider(){
    return new Object[][] 
        {
            { "Android_6.0_Phone..." },
            { "Android_7.0_Phone..." },
            { "Android_8.0_Phone..." }
        };
    }

Now Your test should look like this:

 @Test(dataProvider="DeviceCapabilityProvider" , dataproviderthreadcount = 3)
    public void testMethod(String myDevice){
    {
      // Create driver here or outside the class

      DesiredCapabilities caps; 
      caps.setCapability(MobileCapabilityType.DEVICE_NAME,myDevice);
      AppiumDriver driver=new AndroidDriver(url,caps);

      // Add test steps
    }

Note: In case dataproviderthreadcount didin't work try to use threadPoolSize instead but it should work.

References:

http://testng.org/doc/documentation-main.html#running-testng https://learn.techbeacon.com/units/how-use-testng-parallel-test-execution https://wiki.saucelabs.com/display/DOCS/Parallel+Testing+in+Java+with+Maven+and+TestNG TestNG parallel Execution with DataProvider

Nael Marwan
  • 1,030
  • 1
  • 13
  • 32