Parallel WebDriver executions using TestNG
I am using -selenium-server-2.35.0 jar and selenium-java-2.42.2
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Parameters;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@Listeners()
public class Browser
{
WebDriver driver;
@BeforeMethod
@Parameters({"browser"})
public void openBroswer(String browser)
{
System.out.println(browser);
if(browser.equalsIgnoreCase("FF"))
{
System.out.println("Firefox driver would be used");
driver = new FirefoxDriver();
}
else
{
System.out.println("Ie webdriver would be used");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("webdriver.ie.driver","E:\\IEDriverServer_Win32_2.27.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver(capabilities);
}
}
@AfterMethod
public void closeBrowser()
{
driver.close();
driver.quit();
}
@Test
public void test1()
{
driver.get("http://www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("selenium");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.findElement(By.xpath("//ol[@id='rso']/li[1]//h3/a")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}}}
TestNG xml file, need to run this file
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite1" verbose="1" parallel="tests">
<listeners>
<listener class-name="com.test.listeners.SeleniumStarterListener"/>
</listeners>
<test name="Generic test" >
<parameter name="browser" value="FF"></parameter>
<classes>
<class name="Browser" />
</classes>
</test>
<test name="Generic test_ie" >
<parameter name="browser" value="IE"></parameter>
<classes>
<class name="Browser" />
</classes>
</test>
</suite>
Selenumn Blog by hitesh singh
I am using -selenium-server-2.35.0 jar and selenium-java-2.42.2
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Parameters;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@Listeners()
public class Browser
{
WebDriver driver;
@BeforeMethod
@Parameters({"browser"})
public void openBroswer(String browser)
{
System.out.println(browser);
if(browser.equalsIgnoreCase("FF"))
{
System.out.println("Firefox driver would be used");
driver = new FirefoxDriver();
}
else
{
System.out.println("Ie webdriver would be used");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("webdriver.ie.driver","E:\\IEDriverServer_Win32_2.27.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver(capabilities);
}
}
@AfterMethod
public void closeBrowser()
{
driver.close();
driver.quit();
}
@Test
public void test1()
{
driver.get("http://www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("selenium");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.findElement(By.xpath("//ol[@id='rso']/li[1]//h3/a")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}}}
TestNG xml file, need to run this file
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite1" verbose="1" parallel="tests">
<listeners>
<listener class-name="com.test.listeners.SeleniumStarterListener"/>
</listeners>
<test name="Generic test" >
<parameter name="browser" value="FF"></parameter>
<classes>
<class name="Browser" />
</classes>
</test>
<test name="Generic test_ie" >
<parameter name="browser" value="IE"></parameter>
<classes>
<class name="Browser" />
</classes>
</test>
</suite>
Selenumn Blog by hitesh singh
No comments:
Post a Comment