1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.qa.glnm.interaction;
21
22 import static io.wcm.qa.glnm.webdriver.WebDriverManagement.getWait;
23
24 import java.util.function.Function;
25
26 import org.openqa.selenium.JavascriptExecutor;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.support.ui.ExpectedConditions;
29 import org.openqa.selenium.support.ui.WebDriverWait;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34
35
36
37
38 public final class Wait {
39
40 private static final int DEFAULT_TIMEOUT = 1;
41
42 private static final Logger LOG = LoggerFactory.getLogger(Wait.class);
43
44 private Wait() {
45
46 }
47
48
49
50
51
52
53 public static void forDomReady() {
54 forDomReady(DEFAULT_TIMEOUT);
55 }
56
57
58
59
60
61
62
63 public static void forDomReady(int timeOutInSeconds) {
64 WebDriverWait wait = getWait(timeOutInSeconds);
65 wait.until(driver -> ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete"));
66 }
67
68
69
70
71
72
73
74 public static void forUrl(String url) {
75 forUrl(url, DEFAULT_TIMEOUT);
76 }
77
78
79
80
81
82
83
84
85 public static void forUrl(String url, int timeOutInSeconds) {
86 if (LOG.isTraceEnabled()) {
87 LOG.trace("waiting for URL: '" + url + "'");
88 }
89 WebDriverWait wait = getWait(timeOutInSeconds);
90 wait.until((Function<? super WebDriver, Boolean>)ExpectedConditions.urlToBe(url));
91 if (LOG.isTraceEnabled()) {
92 LOG.trace("found URL: '" + url + "'");
93 }
94 }
95
96 }