Prerequisites:
1.Install TestNG in Eclipse using the URL:http://beust.com/eclipse
2.Download WebDriver package from the location link
3.Download Selenium-server jar file from the location link
I have created 2 sample scripts for demo :
sample.java
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.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class sample {
WebDriver d;
@BeforeMethod
public void BM() throws MalformedURLException
{
DesiredCapabilities capability=null;
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
d = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
d.get("http://google.com");
}
@Test
public void test()
{
System.out.print("test");
}
@AfterMethod
public void AM()
{
d.quit();
}
}
sample1.java
import java.net.MalformedURLException;
1.Install TestNG in Eclipse using the URL:http://beust.com/eclipse
2.Download WebDriver package from the location link
3.Download Selenium-server jar file from the location link
I have created 2 sample scripts for demo :
sample.java
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.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class sample {
WebDriver d;
@BeforeMethod
public void BM() throws MalformedURLException
{
DesiredCapabilities capability=null;
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
d = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
d.get("http://google.com");
}
@Test
public void test()
{
System.out.print("test");
}
@AfterMethod
public void AM()
{
d.quit();
}
}
sample1.java
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.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class sample1 {
WebDriver d;
@BeforeMethod
public void BM() throws MalformedURLException
{
DesiredCapabilities capability=null;
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
d = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
d.get("http://google.com");
}
@Test
public void test()
{
System.out.print("test");
}
@AfterMethod
public void AM()
{
d.quit();
}
}
TestNG.XML
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Selenium Grid with webdriver" verbose="3" parallel="classes" thread-count="2">
<test name="Selenium Grid Demo">
<parameter name="browser" value="firefox"/>
<classes>
<class name="packagename.sample"/>
<class name="packagename.sample1"/>
</classes>
</test>
</suite>
Now to start the Grid and Node: open CMD and navigate to selenium-server-standalone-x.x.x.jar file is located and use the following commands
Create hub using below command
java -jar selenium-server-standalone-2.33.0.jar -role hub
Create node using below command
java -jar selenium-server-standalone-2.33.0.jar -role webdriver -hub http://localhost:4444/grid/register
Create another node using below command
java -jar selenium-server-standalone-2.33.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556
Note:You can create N number of nodes,but give different port number for each node
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class sample1 {
WebDriver d;
@BeforeMethod
public void BM() throws MalformedURLException
{
DesiredCapabilities capability=null;
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
d = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
d.get("http://google.com");
}
@Test
public void test()
{
System.out.print("test");
}
@AfterMethod
public void AM()
{
d.quit();
}
}
TestNG.XML
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Selenium Grid with webdriver" verbose="3" parallel="classes" thread-count="2">
<test name="Selenium Grid Demo">
<parameter name="browser" value="firefox"/>
<classes>
<class name="packagename.sample"/>
<class name="packagename.sample1"/>
</classes>
</test>
</suite>
Now to start the Grid and Node: open CMD and navigate to selenium-server-standalone-x.x.x.jar file is located and use the following commands
Create hub using below command
java -jar selenium-server-standalone-2.33.0.jar -role hub
Create node using below command
java -jar selenium-server-standalone-2.33.0.jar -role webdriver -hub http://localhost:4444/grid/register
Create another node using below command
java -jar selenium-server-standalone-2.33.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556
Note:You can create N number of nodes,but give different port number for each node
No comments:
Post a Comment