- Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathSample9.java
More file actions
Latest commit
103 lines (81 loc) · 3.65 KB
/
Copy pathSample9.java
File metadata and controls
103 lines (81 loc) · 3.65 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
packageselenium.sample;
importorg.junit.After;
importorg.junit.Before;
importorg.junit.Test;
importorg.openqa.selenium.By;
importorg.openqa.selenium.StaleElementReferenceException;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
importorg.openqa.selenium.support.ui.ExpectedConditions;
importorg.openqa.selenium.support.ui.WebDriverWait;
importjava.io.File;
importjava.util.concurrent.TimeUnit;
importstaticorg.junit.Assert.assertEquals;
publicclassSample9 {
WebDriverdriver;
privatestaticWebDriverWaitwait;
staticlongstartTime;
@Before
publicvoidopenPage() {
StringlibWithDriversLocation = System.getProperty("user.dir") + File.separator + "lib" + File.separator;
System.setProperty("webdriver.chrome.driver", libWithDriversLocation + "chromedriver" + newselenium.ChangeToFileExtension().extension());
driver = newChromeDriver();
wait = (WebDriverWait) newWebDriverWait(driver, 10).ignoring(StaleElementReferenceException.class);
driver.get("https://kristinek.github.io/site/examples/sync");
System.out.println(driver.findElement(By.id("magic_text")).getText());
assertEquals("This text magicly changes color", driver.findElement(By.id("magic_text")).getText());
startTime = System.currentTimeMillis();
}
publicvoidmagicTextCheck() {
System.out.println(driver.findElement(By.id("magic_text")).getText());
assertEquals("What is this magic? It's dev magic~", driver.findElement(By.id("magic_text")).getText());
}
@After
publicvoidcloseBrowser() {
longendTime = System.currentTimeMillis();
System.out.println("Total time was: " + (endTime - startTime));
driver.close();
}
@Test
publicvoidsleepExample() throwsException {
Thread.sleep(10000);
magicTextCheck();
}
@Test
publicvoidimplicitWaitExample() throwsException {
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='magic_text']/*[text()=\"What is this magic? It's dev magic~\"]"));
// driver.findElement(By.id("asd"));
magicTextCheck();
}
@Test
publicvoidexplicitWaitExample1() throwsException {
// check that the element is present on page
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='magic_text']/*[text()=\"What is this magic? It's dev magic~\"]")));
// wait.until(ExpectedConditions.presenceOfElementLocated(By.id("asd")));
// driver.findElement(By.xpath("//*[@id='magic_text']/*[text()=\"What is this magic? It's dev magic~\"]"));
magicTextCheck();
}
@Test
publicvoidexplicitWaitExample2() throwsException {
// check that the element is not visible on page
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id='magic_text']/*[text()=\"What is this magic? It's dev magic~\"]")));
magicTextCheck();
}
@Test
publicvoidexplicitWaitExample3() throwsException {
driver.get("https://kristinek.github.io/site/examples/alerted_page");
wait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();
}
@Test
publicvoidexplicitWaitExample4() throwsException {
wait.until(ExpectedConditions.attributeContains(By.xpath("//p"), "style", "color: rgb(119, 119, 119);"));
magicTextCheck();
}
@Test
publicvoidexplicitWaitExample5() throwsException {
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//p"), "dev"));
magicTextCheck();
}
}