5.2 Object Repository
package com.selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class WithoutOR {
private WebDriver driver;
private String baseUrl;
@BeforeTest
public void initialization() {
driver = new FirefoxDriver();
baseUrl = "http://docs.seleniumhq.org/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@Test
public void testMethod() throws InterruptedException {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("Projects")).click();
driver.findElement(By.linkText("nsaikiran")).click();
Assert.assertTrue(isElementPresent(By.name("submit")));
}
@AfterTest
public void cleanup() {
driver.quit();
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}Last updated