package parallel;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class CrossBrowserTest {
private WebDriver driver;
// Configuration for cross browser
@Parameters("browser")
@BeforeClass
public void beforeTest(String browser) {
if (browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
}
else if (browser.equalsIgnoreCase("chrome")) {
// Set Path for the executable file
System.setProperty("webdriver.chrome.driver","F:\\\\Jar\\\\chromedriver.exe");
driver = new ChromeDriver();
}
else if (browser.equalsIgnoreCase("ie")) {
// Set Path for the executable file
System.setProperty("webdriver.ie.driver", "F:\\\\Jar\\\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
else {
throw new IllegalArgumentException("The Browser Type is Undefined");
}
}
@Test
public void multiBrowser() throws Exception {
//Open URL
driver.get("http://bing.com");
//Search for testerinyou blog
driver.findElement(By.id("sb_form_q")).sendKeys("testerinyou.blogspot.in");
//click search button
driver.findElement(By.id("sb_form_go")).click();
//in results page click the link
driver.findElement(By.partialLinkText("Selenium IDE, Selenium RC and Webdriver")).click();
Thread.sleep(5000);
}
@AfterClass
public void afterTest() {
driver.quit();
}
}