Repository navigation
Expand file tree
/
Copy pathtest1
More file actions
53 lines (52 loc) · 1.64 KB
/
Copy pathtest1
File metadata and controls
53 lines (52 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestLogin {
private WebDriver driver;
@Before
public void setUp() {
driver = new FirefoxDriver();
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void succeeded() {
driver.get("http://the-internet.herokuapp.com/login");
driver.findElement(By.id("username")).
sendKeys("tomsmith");
driver.findElement(By.id("password")).
sendKeys("SuperSecretPassword!");
driver.findElement(By.cssSelector("button")).click();
assertTrue("success message not present",
driver.findElement(
By.cssSelector(".flash.success")).isDisplayed());
}
}
//Page Objects
public class Login {
By loginFormLocator = By.id("login");
By usernameLocator = By.id("username");
By passwordLocator = By.id("password");
By submitButton = By.cssSelector("button");
By successMessageLocator = By.cssSelector(".flash.success");
public Login(WebDriver driver) {
this.driver = driver;
driver.get("http://the-internet.herokuapp.com/login");
assertTrue("The login form is not present",
driver.findElement(loginFormLocator).isDisplayed());
}
public void with(String username, String password) {
driver.findElement(usernameLocator).sendKeys(username);
driver.findElement(passwordLocator).sendKeys(password);
driver.findElement(submitButton).click();
}
public Boolean successMessagePresent() {
return driver.findElement(successMessageLocator).isDisplayed();
}
}