-
Notifications
You must be signed in to change notification settings - Fork 20
/
Sample10.java
72 lines (61 loc) · 2.37 KB
/
Sample10.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
67
68
69
70
71
72
package selenium.sample;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
import selenium.pages.AgeSamplePage;
import selenium.pages.AgeSubmittedSamplePage;
import java.io.File;
import java.util.concurrent.TimeUnit;
public class Sample10 {
static WebDriver driver;
static AgeSamplePage agePage;
static AgeSubmittedSamplePage ageSubmittedPage;
@Before
public void openPage() throws InterruptedException {
String libWithDriversLocation = System.getProperty("user.dir") + File.separator + "lib" + File.separator;
System.setProperty("webdriver.chrome.driver", libWithDriversLocation + "chromedriver" + new selenium.ChangeToFileExtension().extension());
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://kristinek.github.io/site/examples/age");
agePage = PageFactory.initElements(driver, AgeSamplePage.class);
ageSubmittedPage = PageFactory.initElements(driver, AgeSubmittedSamplePage.class);
}
@After
public void closeBrowser() {
driver.close();
}
@Test
public void checkCleanPage() throws Exception {
agePage.checkThatFormIsClean();
}
@Test
public void checkErrorMessageOnEmptyAge() throws Exception {
agePage.clickSubmit();
agePage.checkErrorMessage("You haven't entered anything in age field");
}
@Test
public void checkErrorMessageOnEmptyName() throws Exception {
agePage.enterAge(3);
agePage.clickSubmit();
agePage.checkErrorMessage("You haven't entered anything in name field");
}
@Test
public void checkSuccessfulMessageForKid() throws Exception {
agePage.enterNameAgeAndClickSubmit("Ann", 5);
ageSubmittedPage.checkMessageText("Hello, Ann, you are a kid");
}
@Test
public void checkSuccessfulMessageForAdult() throws Exception {
agePage.enterNameAgeAndClickSubmit("Tom", 55);
ageSubmittedPage.checkMessageText("Hello, Tom, you are an adult");
}
@Test
public void checkBackButton() throws Exception {
agePage.enterNameAgeAndClickSubmit("Tom", 55);
ageSubmittedPage.clickBackButton();
agePage.checkThatFormIsClean();
}
}