0

Run tests in three browsers (chrome, firefox and ie) parallely. Each browser should open 2 instances. In total, on triggering testng.xml , 6 browser instances should be opened.

<suite thread-count=3 parallel="tests">
 <test>
  for firefox
 </test>

 <test>
  for chrome
 </test>

 <test>
  for ie
 </test>
</suite>

Please help me!

rama krishna
  • 35
  • 1
  • 8

2 Answers2

0

In your TestNG.xml file , add a parameter for specifying browser type.

 <test>
  <parameter name="browser" value="firefox">
  <parameter name="username" value="testuser"/>
  <parameter name="password" value="testpassword"/>
    <classes>
        <class name="com.parameterization.TestParameters" />
    </classes>
 </test>

 <test>
  <parameter name="browser" value="chrome">
  <parameter name="username" value="testuser"/>
  <parameter name="password" value="testpassword"/>
    <classes>
        <class name="com.parameterization.TestParameters" />
    </classes>
 </test>

 <test>
  <parameter name="browser" value="ie">
  <parameter name="username" value="testuser"/>
  <parameter name="password" value="testpassword"/>
    <classes>
        <class name="com.parameterization.TestParameters" />
    </classes>
 </test>
</suite>

In your test class receive these parameters and create a webdriver according to the desired capabilities.

package com.parameterization;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class TestParameters {

    @Parameters({ "browser", "username", "password" })
    @Test
    public void testCaseOne(String browser,String username, String password) {
        System.out.println("browser passed as :- " + browser);
        createWebDriver(browser);
        loginToApplicationOne(username,password);   

    }

    @Parameters({ "browser", "username", "password" })
    @Test
    public void testCaseTwo(String browser, String username, String password) {
    createWebDriver(browser);
    loginToApplicationTwo(username,password);       
    }
} 

As you have set thread-count to 3 and your requirement is to launch 2 browser instances in each test block. You have to refactor your test classes in the above style so that each method block create its isolated driver instance. Thus a total of 6 browsers would be launched.

Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29
  • Thanks, My requirement is to run same tests in both the browser instances simultaneously. for example, in both instances of ff browser, same test case (test1) should be running – rama krishna Nov 26 '17 at 08:09
  • Copy the class tag 2 times in the xml , change the parallel attribute to "classes" and thread count to 6. – Manmohan_singh Nov 26 '17 at 08:21
0

There is no clean way to do this through xml just workarounds.

You can add the invocationCount to the @Test annotation for the test you want to repeat. Refer to link for more details.

Also you could create a duplicate of the xml file and run them as parallel suites using -suitethreadpoolsize as argument. Also pass in both the xml files as argument. Refer to link for doc.

Plus as suggested in the answers before, copying the tests multiple times in same xml.

Grasshopper
  • 8,908
  • 2
  • 17
  • 32