July 4, 2011

Selenium 2.0 Sample program

Here is my first post..related to Selenium 2.0 ...

This script is to search for "selenium"  on google...

Below is code with comments..


package setup;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.thoughtworks.selenium.Selenium;

public class Default {

WebDriver driver;
Selenium selenium;

@BeforeMethod
public void startSelenium() {
//driver = new FirefoxDriver();  //--To run tests on FF
//Internet Explorer Driver --to Run test in IE
driver = new InternetExplorerDriver();
//driver = new ChromeDriver(); //Chrome Driver -- to run tests in google Chrome
/*Below command is optional if we want to use Selenium commands 
instead of selenium2 we have to declare this*/
//selenium = new WebDriverBackedSelenium(driver, "http://www.pdfonline.com/");
}

@AfterMethod
public void stopSelenium() {
//Closing the Driver
driver.close();
}

@Test
public void testAlert() throws Exception {
//Open Home Page
driver.get("http://www.google.com");
//Enter text in search box
driver.findElement(By.name("q")).sendKeys("selenium");
Thread.sleep(1000);
//Click Search button
driver.findElement(By.name("btnG")).click();
Thread.sleep(10000);


}

}

1 comment:

  1. test a program to provide total number of objects present / available on the page

    ReplyDelete