2.1 Setting up Browsers
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();
}
}Last updated