Reputation: 161
I am new to selenium,I need to run my single selenium test case in two different nodes using FIREFOX browser (selenium grid),I have started my hub using below command
java -jar selenium-server-standalone-2.32.0.jar -role hub
Node 1: java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 9595
Node 2: java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 8585
two nodes has been created to hub .But when i run a testcase in hub,only one node is executing the test case and the other node remain available but not executing the testcase .
2) The node is selected randomly by hub while executing the testcase.
My question: Run testcase in both the nodes simultaneously
Upvotes: 0
Views: 5079
Reputation: 896
Nodes can be declared as follow:-
Node 1 for chrome java -Dwebdriver.chrome.driver=C:\drivers\chromedriver.exe -jar selenium-server-standalone-2.44.0.jar -role node -hub http://localhost:4444/grid/register -port 8585 -browserName=chrome
Node 2 for firefox: java -jar selenium-server-standalone-2.44.0.jar -role node -hub http://localhost:4444/grid/register -port 9595 -browserName=firefox
You need to have following testng.xml to run same test case on different browsers:-
<suite name="Selenium TestNG Suite" parallel="tests" thread-count="5">
<test name="Selenium TestNG - 1">
<parameter name="browser" value="firefox" />
<parameter name="port" value="9595" />
<classes>
<class name="grid.testcase" />
</classes>
</test>
<test name="Selenium TestNG - 2">
<parameter name="browser" value="chrome" />
<parameter name="port" value="8585" />
<classes>
<class name="grid.testcase" />
</classes>
</test>
</suite>
In your test case, write code something like this:-
package grid;
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.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class testcase {
public WebDriver driver=null;
@Parameters({"browser","port"})
@BeforeClass
public void initialize(String browser, String port) throws MalformedURLException{
DesiredCapabilities capability= new DesiredCapabilities();
capability.setBrowserName(browser);
driver= new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capability);
}
@Test
public void testThis() throws InterruptedException {
String url="https://www.google.com";
driver.get(url);
driver.manage().window().maximize();
//do something
driver.close();
}
}
Upvotes: 2
Reputation: 48
Refer :
Upvotes: 0