@@ -29,15 +29,24 @@ private PageObjectUtilities(){
2929 * @param driver the web driver
3030 * @param urlRegex the regular expression that the url must match
3131 */
32- public static void waitForiPageToHaveMatchingUrl (WebDriver driver , String urlRegex ) {
32+ public static void waitForPageToHaveMatchingUrl (WebDriver driver , String urlRegex ) {
33+ waitForPageToHaveMatchingUrl (driver , urlRegex , Duration .ofSeconds (25 ));
34+ }
35+
36+ /**
37+ * Waits for page to have a matching url.
38+ * @param driver the web driver
39+ * @param urlRegex the regular expression that the url must match
40+ * @param timeout the timeout
41+ */
42+ public static void waitForPageToHaveMatchingUrl (WebDriver driver , String urlRegex , Duration timeout ) {
3343 Wait <WebDriver > wait =
3444 new FluentWait <>(driver )
35- .withTimeout (Duration . ofSeconds ( 25 ) )
45+ .withTimeout (timeout )
3646 .pollingEvery (Duration .ofMillis (300 ));
3747
3848 wait .until (ExpectedConditions .urlMatches (urlRegex ));
3949 }
40-
4150
4251
4352 /**
@@ -47,9 +56,20 @@ public static void waitForiPageToHaveMatchingUrl(WebDriver driver, String urlReg
4756 * @return the web element
4857 */
4958 public static WebElement waitForElementToBeInteractable (WebDriver driver , By by ) {
59+
60+ return waitForElementToBeInteractable (driver , by , Duration .ofSeconds (15 ));
61+ }
62+
63+ /**
64+ * Wait for an element to exist and to be interactable.
65+ * @param driver the web driver
66+ * @param by the locator for the element
67+ * @return the web element
68+ */
69+ public static WebElement waitForElementToBeInteractable (WebDriver driver , By by , Duration timeout ) {
5070 Wait <WebDriver > wait =
5171 new FluentWait <>(driver )
52- .withTimeout (Duration . ofSeconds ( 15 ) )
72+ .withTimeout (timeout )
5373 .pollingEvery (Duration .ofMillis (300 ))
5474 .ignoring (NoSuchElementException .class ,ElementNotInteractableException .class );
5575
@@ -64,13 +84,24 @@ public static WebElement waitForElementToBeInteractable(WebDriver driver, By by)
6484 * @return the web element
6585 */
6686 protected static WebElement waitForElementToBeInteractable (WebDriver driver , WebElement element ) {
87+ return waitForElementToBeInteractable (driver , element , Duration .ofSeconds (15 ));
88+ }
89+
90+ /**
91+ * Wait if passed element is interactable.
92+ * @param driver the web driver
93+ * @param element the element to wait for the condition
94+ * @param timeout the timeout to use
95+ * @return the web element
96+ */
97+ protected static WebElement waitForElementToBeInteractable (WebDriver driver , WebElement element , Duration timeout ) {
6798 if (element == null ) {
6899 return null ;
69100 }
70101
71102 Wait <WebDriver > wait =
72103 new FluentWait <>(driver )
73- .withTimeout (Duration . ofSeconds ( 15 ) )
104+ .withTimeout (timeout )
74105 .pollingEvery (Duration .ofMillis (300 ))
75106 .ignoring (ElementNotInteractableException .class );
76107
@@ -85,6 +116,17 @@ protected static WebElement waitForElementToBeInteractable(WebDriver driver, Web
85116 * @return the web element
86117 */
87118 public static WebElement waitForElementToBePresent (WebDriver driver , By by ) {
119+ return waitForElementToBePresent (driver , by , Duration .ofSeconds (15 ));
120+ }
121+
122+ /**
123+ * Wait for element to be present.
124+ * @param driver web driver
125+ * @param by the locator to use
126+ * @param timeout the timeout to use
127+ * @return the web element
128+ */
129+ public static WebElement waitForElementToBePresent (WebDriver driver , By by , Duration timeout ) {
88130 Wait <WebDriver > wait =
89131 new FluentWait <>(driver )
90132 .withTimeout (Duration .ofSeconds (15 ))
@@ -94,16 +136,27 @@ public static WebElement waitForElementToBePresent(WebDriver driver, By by) {
94136 return wait .until (ExpectedConditions .presenceOfElementLocated (by ));
95137
96138 }
139+
97140
98141 /**
99142 * Wait for element to be absent
100143 * @param driver the web driver
101144 * @param element the web element to check
102145 */
103146 public static void waitForElementToBeAbsent (WebDriver driver , WebElement element ) {
147+ waitForElementToBeAbsent (driver , element , Duration .ofSeconds (15 ));
148+ }
149+
150+ /**
151+ * Wait for element to be absent
152+ * @param driver the web driver
153+ * @param element the web element to check
154+ * @param timeout the timeout to use
155+ */
156+ public static void waitForElementToBeAbsent (WebDriver driver , WebElement element , Duration timeout ) {
104157 Wait <WebDriver > wait =
105158 new FluentWait <>(driver )
106- .withTimeout (Duration . ofSeconds ( 15 ) )
159+ .withTimeout (timeout )
107160 .pollingEvery (Duration .ofMillis (300 ));
108161
109162 wait .until (ExpectedConditions .stalenessOf (element ));
@@ -121,7 +174,17 @@ public static void waitUntilPageSourceContains(WebDriver driver, String text) {
121174
122175 }
123176
124-
177+ /**
178+ * Wait until page source contains.
179+ * @param driver the web driver
180+ * @param text the test to search
181+ * @param timeout the timeout to ise
182+ */
183+ public static void waitUntilPageSourceContains (WebDriver driver , String text , Duration timeout ) {
184+
185+ waitForElementToBePresent (driver , By .xpath ("//*[text()[contains(.,'" + text + "')]]" ), timeout );
186+
187+ }
125188
126189
127190 public static void doPageRefresh (WebDriver driver ) {
0 commit comments