0

I'm using selenium-grid, and want to how to start my tests in parallel on the same browser, for example: Chrome

The problem is, Chrome keeps opening only one instance util the first test is finished, and then start the next test.

Please help me :)

public WebDriver createDriverGrid() throws MalformedURLException {
        String hubUrl = "http://localhost:4446/wd/hub";
        ChromeOptions capabilities = new ChromeOptions();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
        driver.set(new RemoteWebDriver(new URL(hubUrl), capabilities));
        return driver.get();
    }

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="GoogleTestSuite" verbose="2" parallel="tests" thread-count="2" preserve-order="true">


    <test name="GoogleTest-CH" parallel="true">
    <!--<parameter name="browser" value="chrome"></parameter>-->
     <classes>
        <class name="com.herokuapp.theinternet.tests.GoogleTests" />
     </classes>
   </test>

</suite>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="PositiveTestSuite" verbose="2" parallel="tests" thread-count="2" preserve-order="true">
    <test name="PositiveTest-CH" parallel="true">
     <classes>
        <class name="com.herokuapp.theinternet.tests.PositiveTests" />
         <!--<class name="com.herokuapp.theinternet.tests.PositiveTests" />-->
     </classes>
   </test>
</suite>
  • 1
    Welcome to SO. Where is `createDriverGrid` method? is it part of `@BeforeClass`? – supputuri Mar 22 '19 at 23:39
  • It's a part of @BeforeMethod. ``` @BeforeMethod(alwaysRun = true) protected void setUp() throws MalformedURLException { // Create Driver BrowserDriverFactory factory = new BrowserDriverFactory(); setCurrentThreadName(); driver = factory.createDriverGrid(); // maximize browser window driver.manage().window().maximize(); } ``` – Qasim Maghaireh Mar 23 '19 at 11:22
  • Also want to know if you have enough nodes to run the parallel scripts. – supputuri Mar 23 '19 at 14:20

2 Answers2

1

If you want to start the test in parallel executing then you write a twice of your test method. As per your TestNG.xml, you have to write parallel="tests" thread-count="2" that means there has two test method which we want to execute parallelly.

Kindly replace your xml with below code:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="PositiveTestSuite" parallel="tests" thread-count="2">

    <test name="PositiveTest-CH">
     <classes>
        <class name="com.herokuapp.theinternet.tests.PositiveTests" />
     </classes>
   </test>

   <test name="PositiveTest-CH1">
     <classes>
        <class name="com.herokuapp.theinternet.tests.PositiveTests" />
     </classes>
   </test>

</suite>

Try this it will be working fine.

Amit Singh
  • 121
  • 5
0

You can achieve this by using jenkins pipelines, without having to modify your source code