I have configured grid in my system and written my test script. I can run my test on any specified OS and any Browser but only on one OS and one Browser at one time not all OS and all Browser simultaneously. Here is what I have done. Please tell me how can I configure it so that it can run in configured OS in one time.
My Script using Java is below:
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.AfterClass;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class GridWithWebdriver {
public WebDriver driver;
@Parameters({"browser"})
@BeforeClass
public void setup(String browser) throws MalformedURLException {
DesiredCapabilities capability=null;
if(browser.equalsIgnoreCase("firefox")){
System.out.println("firefox");
capability= DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
//capability.setVersion("");
}
if(browser.equalsIgnoreCase("iexplore")){
System.out.println("iexplore");
capability= DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
//capability.setVersion("");
}
driver = new RemoteWebDriver(<span class="IL_AD" id="IL_AD11">new URL</span>("http://localhost:4444/wd/hub"), capability);
driver.navigate().to("http://google.com");
}
@Test
public void test_first() throws InterruptedException{
Thread.sleep(3000);
WebElement search_editbox = driver.findElement(By.name("q"));
WebElement search_button = driver.findElement(By.name("btnG"));
search_editbox.clear();
search_editbox.sendKeys("first");
search_button.click();
}
@Test
public void test_second(){
WebElement search_editbox = driver.findElement(By.name("q"));
WebElement search_button = driver.findElement(By.name("btnG"));
search_editbox.clear();
search_editbox.sendKeys("second");
search_button.click();
}
@AfterClass
public void tearDown(){
driver.quit();
}
}
Testng.xml:
<suite name="Selenium <span class="IL_AD" id="IL_AD7">Grid with</span> webdriver" verbose="3" parallel="classes" thread-count="2">
<test name="Selenium Grid Demo">
<parameter name="browser" value="iexplore"/>
<classes>
<class name="tests.GridWithWebdriver"/>
<class name="tests.GridWithWebdriver1"/>
</classes>
</test>
</suite>
Aditya,
Your code(testng.xml) for running parallel test on different-different or same system should be like below:
Testng.xml
<!DOCTYPE suite SYSTEM "Http://testng.org/testng-1.0.dtd">
<suite name="My Sample Suite" verbose="3" parallel="tests" thread-count="2">
<test name="Run on Firefox">
<parameter name="mybrowser" value="firefox"/>
<parameter name="myip" value="http://172.16.10.119:5566/wd/hub"/>
<classes>
<class name="testcases.Login"/>
</classes>
</test>
<test name="Run on Chrome">
<parameter name="mybrowser" value="chrome"/>
<parameter name="myip" value="http://172.16.10.106:5567/wd/hub"/>
<classes>
<class name="testcases.Login"/>
</classes>
</test>
</suite>
here i am trying to acess one linux(ttp://172.16.10.119:5566) and one mac(http://172.16.10.106:5567) and sending its ip and browser as a parameter. To run it parallel i have mentioned in my <testsuite> tag as parallel="tests" thread-count="2"
I hope that you are pretty clear now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With