-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAgeSamplePage.java
66 lines (53 loc) · 1.9 KB
/
AgeSamplePage.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
package selenium.pages;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import static org.junit.Assert.*;
public class AgeSamplePage extends GenericSamplePage {
@FindBy(how = How.ID, using = "name") // By.id("name")
private WebElement nameInput; // WebElement nameInput = driver.findElement(By.id("name"));
@FindBy(how = How.NAME, using = "age") // By.name("age")
private WebElement ageInput;
@FindBy(how = How.ID, using = "submit")
private WebElement submitButton;
@FindBy(how = How.CLASS_NAME, using = "error") // By.className("error)
private WebElement errorText;
public void enterName(String name) {
nameInput.clear();
nameInput.sendKeys(name);
}
public void enterAge(int age) {
enterAge(String.valueOf(age));
}
public void enterAge(String age) {
ageInput.clear();
ageInput.sendKeys(age);
}
public void clickSubmit() {
submitButton.click();
}
public void enterNameAgeAndClickSubmit(String name, int age) {
enterNameAgeAndClickSubmit(name, String.valueOf(age));
}
public void enterNameAgeAndClickSubmit() {
enterName("admib");
enterAge("pass");
submitButton.click();
}
public void enterNameAgeAndClickSubmit(String name, String age) {
enterName(name);
enterAge(age);
submitButton.click();
}
public void checkErrorMessage(String errorMessage) {
checkPageHeaderText("Age page");
assertEquals(errorText.getText(), errorMessage);
assertTrue(errorText.isDisplayed());
}
public void checkThatFormIsClean() {
checkPageHeaderText("Age page");
assertEquals(nameInput.getAttribute("value"), "Enter name here");
assertEquals(ageInput.getAttribute("value"), "");
assertFalse(errorText.isDisplayed());
}
}