0
votes

I have Selenium Grid2 with a hub and two nodes.

Hub is operated by:

java -jar selenium-server-standalone-2.32.0.jar -role hub -port 4444

Nodes are operated by:

java -jar selenium-server-standalone-2.32.0.jar -role node -hub http://10.20.46.171:4444/wd/hub -port 5555

In hub console, I see both nodes up and running.

My TestNB config (testng.xml):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Full suite" parallel="classes" thread-count="4">
  <parameter name="hubAddress" value="http://127.0.0.1:4444/wd/hub"></parameter>
  <test verbose="2" name="Full">
    <packages>
      <package name="com.example.tests">
      </package>
    </packages>
  </test>
</suite>

In com/example/tests, I have a base class TestBase and 4 other classes that extend TestBase

In TestBase.java, I have:

package com.example.tests;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;

public class TestBase {

  protected WebDriver driver;

  @BeforeClass
  @Parameters("hubAddress")
  public void startDriver(String hubAddress) throws MalformedURLException {
    driver = new RemoteWebDriver(new URL(hubAddress), DesiredCapabilities.Firefox());
  }

  @AfterClass
  public void stopDriver() {
    driver.quit();
    driver = null;
  }

}

In Test1.java, I have:

package com.example.tests;
import org.testng.annotations.Test;

@Test
public class Test1 extends TestBase {

  public void test1() {
    driver.get("http://www.google.com/");
  }

}

In Test2.java, I have:

package com.example.tests;
import org.testng.annotations.Test;

@Test
public class Test2 extends TestBase {

  public void test2() {
    driver.get("http://www.facebook.com/");
  }

}

In Test3.java, I have:

package com.example.tests;
import org.testng.annotations.Test;

@Test
public class Test3 extends TestBase {

  public void test3() {
    driver.get("http://www.yahoo.com/");
  }

}

In Test4.java, I have:

package com.example.tests;
import org.testng.annotations.Test;

@Test
public class Test4 extends TestBase {

  public void test4() {
    driver.get("http://www.cnn.com/");
  }

}

I run all this with Ant. Here is a piece of code:

   <target name="run-tests" depends="build">
        <testng classpathref="LoadTests.classpath">
            <xmlfileset dir="." includes="testng.xml"/>
        </testng>
    </target>

The command line:

ant run-tests

How it works now: Test1 runs on Node1 and Test2 runs on Node2 (simultaneously). AFTER THAT, Test3 runs on Node1 and Test4 runs on Node2 (simultaneously).

Desired behavior: All four tests run simultaneously in one shot: two on one node (say, Test1, Test3) and other two on the second node (Test2, Test4).

Question: What should I change so that it works as desired?

1

1 Answers

1
votes

Try using @BeforeMethod instead of @BeforeClass. I know this will create a driver per method, but I think this is the only way if the @Before*annotation* occurs within the base class.

I don't quite understand why this occuring but I have teh same set up as you except use @BeforeMethod, and all is fine when running parallel threads