Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test.java;
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.AfterClass;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.chrome.ChromeDriver;
- public class Demo {
- private WebDriver driver;
- String url = "http://the-internet.herokuapp.com";
- @Before
- public void setup() {
- String driverPath = "D:\\Favorites\\Documents\\Programming\\Java\\eclipse-workspace\\chromedriver.exe";
- System.setProperty("webdriver.chrome.driver", driverPath);
- driver = new ChromeDriver();
- driver.get(url);
- }
- @Test
- public void test() throws InterruptedException {
- //Wait until page title is available and retrieve it, then print it
- String pageTitle = "";
- do {
- pageTitle = driver.getTitle();
- Thread.sleep(10);
- } while (pageTitle == "");
- System.out.println("Page title: " + pageTitle);
- //Click on "Form Authentication"
- driver.findElement(By.linkText("Form Authentication")).click();
- //Wait until page header is available and retrieve it, then print it
- String headerString = "";
- do {
- headerString = driver.findElement(By.tagName("h2")).getText();
- Thread.sleep(10);
- } while (headerString == "");
- System.out.println(headerString);
- //Enter credentials and click "login"
- driver.findElement(By.id("username")).sendKeys("tomsmith");
- driver.findElement(By.id("password")).sendKeys("SuperSecretPassword!");
- driver.findElement(By.xpath("//button[@type='submit]")).click();
- //Wait until page header says "You logged into a secure area!", then print "Login Successful"
- String successString = "";
- do {
- successString = driver.findElement(By.id("flash")).getText();
- Thread.sleep(10);
- } while (successString != "You logged into a secure area!");
- System.out.println("Login Successful");
- }
- @After
- public void after() {
- //Close the browser
- driver.close();
- }
- @AfterClass
- public static void afterClass() {
- System.out.println("Inside after class method.");
- }
- }
Add Comment
Please, Sign In to add comment