forked from yuriy-logosha/selenium_java_basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample9Task.java
More file actions
113 lines (102 loc) · 4.85 KB
/
Sample9Task.java
File metadata and controls
113 lines (102 loc) · 4.85 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
102
103
104
105
106
107
108
109
110
111
112
113
package selenium.sample;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class Sample9Task {
WebDriver driver;
@Before
public void openPage() {
String libWithDriversLocation = System.getProperty("user.dir") + "\\lib\\";
System.setProperty("webdriver.chrome.driver", libWithDriversLocation + "chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://kristinek.github.io/site/examples/loading_color");
}
@After
public void closeBrowser() {
driver.quit();
}
@Test
public void loadGreenSleep() throws Exception {
// * 1) click on start loading green button
WebElement startGreen = driver.findElement(By.cssSelector("#start_green"));
startGreen.click();
TimeUnit.MILLISECONDS.sleep(500);
// * 2) check that button does not appear,
assertFalse(startGreen.isDisplayed());
// * but loading text is seen instead "Loading green..."
WebElement loadingGreen = driver.findElement(By.cssSelector("#loading_green"));
assertTrue(loadingGreen.isDisplayed());
// * 3) check that both button
// * and loading text is not seen,
TimeUnit.MILLISECONDS.sleep(7 * 1000);
assertFalse(startGreen.isDisplayed());
assertFalse(loadingGreen.isDisplayed());
// * success is seen instead "Green Loaded"
WebElement finishGreen = driver.findElement(By.cssSelector("#finish_green"));
assertTrue(finishGreen.isDisplayed());
}
@Test
public void loadGreenImplicit() throws Exception {
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// * 1) click on start loading green button
WebElement startGreen = driver.findElement(By.cssSelector("#start_green"));
startGreen.click();
// * 2) check that button does not appear,
// * but loading text is seen instead "Loading green..."
WebElement loadingGreen = driver.findElement(By.cssSelector("#loading_green"));
assertTrue(loadingGreen.isDisplayed());
assertFalse(startGreen.isDisplayed());
// * 3) check that both button
// * and loading text is not seen,
// * success is seen instead "Green Loaded"
WebElement finishGreen = driver.findElement(By.cssSelector("#finish_green"));
assertTrue(finishGreen.isDisplayed());
assertFalse(startGreen.isDisplayed());
assertFalse(loadingGreen.isDisplayed());
}
@Test
public void loadGreenExplicitWait() throws Exception {
WebDriverWait wait = (WebDriverWait) new WebDriverWait(driver, 10)
.ignoring(StaleElementReferenceException.class);
// * 1) click on start loading green button
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#start_green")));
WebElement startGreen = driver.findElement(By.cssSelector("#start_green"));
startGreen.click();
// * 2) check that button does not appear,
// * but loading text is seen instead "Loading green..."
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#loading_green")));
WebElement loadingGreen = driver.findElement(By.cssSelector("#loading_green"));
assertTrue(loadingGreen.isDisplayed());
assertFalse(startGreen.isDisplayed());
// * 3) check that both button
// * and loading text is not seen,
// * success is seen instead "Green Loaded"
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#finish_green")));
WebElement finishGreen = driver.findElement(By.cssSelector("#finish_green"));
assertTrue(finishGreen.isDisplayed());
assertFalse(startGreen.isDisplayed());
assertFalse(loadingGreen.isDisplayed());
}
@Test
public void loadGreenAndBlueBonus() {
/* TODO:
* 0) wait until button to load green and blue appears
* 1) click on start loading green and blue button
* 2) check that button does not appear, but loading text is seen instead for green
* 3) check that button does not appear, but loading text is seen instead for green and blue
* 4) check that button and loading green does not appear,
* but loading text is seen instead for blue and success for green is seen
* 5) check that both button and loading text is not seen, success is seen instead
*/
}
}