2.1 Setting up Browsers
Selenium supports many browsers, here we provide you with the code to run a few. It is assumed that you have all the necessary jars and tools. Please refer Eclipse Project Setup **for information on how to setup eclipse project.
1. Firefox
package com.selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class BrowserSetup {
WebDriver driver = null;
String baseUrl = null;
@BeforeTest
public void initialization() {
// Create Firfox browser Instance..
driver = new FirefoxDriver();
// Define URL to be opened..
baseUrl = "http://www.google.co.in/";
// Define timeout, selenium will wait maximum of 30 seconds before
// it quits while searching for an element..
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().deleteAllCookies(); // Delete cookies
driver.manage().window().maximize(); // Maximize window
}
@Test
public void testMethod() {
// Open the URL in browser..
driver.get(baseUrl);
}
@AfterTest
public void cleanup() {
// Close the browser..
driver.quit();
}
}2. InternetExplorer (Assuming you have IEDriverServer in your tools directory)
Before Running Internet Explorer from your script please ensure that all the security settings (Tools > Internet Options > Security) are either checked or unchecked.
3. Google Chrome (We assume you have chromedriver in your tools directory)
Last updated
Was this helpful?