| 
46 | 46 | import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElement;  | 
47 | 47 | import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElementLocated;  | 
48 | 48 | import static org.openqa.selenium.support.ui.ExpectedConditions.urlContains;  | 
 | 49 | +import static org.openqa.selenium.support.ui.ExpectedConditions.urlFulfills;  | 
49 | 50 | import static org.openqa.selenium.support.ui.ExpectedConditions.urlMatches;  | 
50 | 51 | import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;  | 
51 | 52 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;  | 
 | 
54 | 55 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfNestedElementsLocatedBy;  | 
55 | 56 | 
 
  | 
56 | 57 | import com.google.common.collect.Sets;  | 
 | 58 | +import java.net.URI;  | 
57 | 59 | import java.time.Duration;  | 
58 | 60 | import java.time.Instant;  | 
59 | 61 | import java.util.ArrayList;  | 
@@ -157,6 +159,43 @@ void negative_waitingForUrlToBeOpened_urlMatches() {  | 
157 | 159 |         .isThrownBy(() -> wait.until(urlMatches(".*\\/malformed.*")));  | 
158 | 160 |   }  | 
159 | 161 | 
 
  | 
 | 162 | +  @Test  | 
 | 163 | +  void waitingForUrlToBeOpened_urlFulfills() {  | 
 | 164 | +    final String url = "https://example.com:8080/path";  | 
 | 165 | +    when(mockDriver.getCurrentUrl()).thenReturn(url);  | 
 | 166 | + | 
 | 167 | +    wait.until(urlFulfills(uri -> "https".equals(uri.getScheme())));  | 
 | 168 | +    wait.until(urlFulfills(uri -> "example.com".equals(uri.getHost())));  | 
 | 169 | +    wait.until(urlFulfills(uri -> uri.getPort() == 8080));  | 
 | 170 | +    wait.until(urlFulfills(uri -> "/path".equals(uri.getPath())));  | 
 | 171 | +  }  | 
 | 172 | + | 
 | 173 | +  @Test  | 
 | 174 | +  void waitingForUrlToBeOpened_urlFulfills_withAbsoluteUrl() {  | 
 | 175 | +    final String url = "https://example.com/absolute/path";  | 
 | 176 | +    when(mockDriver.getCurrentUrl()).thenReturn(url);  | 
 | 177 | + | 
 | 178 | +    wait.until(urlFulfills(URI::isAbsolute));  | 
 | 179 | +  }  | 
 | 180 | + | 
 | 181 | +  @Test  | 
 | 182 | +  void negative_waitingForUrlToBeOpened_urlFulfills() {  | 
 | 183 | +    final String url = "http://example.com/path";  | 
 | 184 | +    when(mockDriver.getCurrentUrl()).thenReturn(url);  | 
 | 185 | + | 
 | 186 | +    assertThatExceptionOfType(TimeoutException.class)  | 
 | 187 | +        .isThrownBy(() -> wait.until(urlFulfills(uri -> "https".equals(uri.getScheme()))));  | 
 | 188 | +  }  | 
 | 189 | + | 
 | 190 | +  @Test  | 
 | 191 | +  void negative_waitingForUrlToBeOpened_urlFulfills_malformedUrl() {  | 
 | 192 | +    final String url = "not-a-valid-url";  | 
 | 193 | +    when(mockDriver.getCurrentUrl()).thenReturn(url);  | 
 | 194 | + | 
 | 195 | +    assertThatExceptionOfType(TimeoutException.class)  | 
 | 196 | +        .isThrownBy(() -> wait.until(urlFulfills(URI::isAbsolute)));  | 
 | 197 | +  }  | 
 | 198 | + | 
160 | 199 |   @Test  | 
161 | 200 |   void waitingForVisibilityOfElement_elementAlreadyVisible() {  | 
162 | 201 |     when(mockElement.isDisplayed()).thenReturn(true);  | 
 | 
0 commit comments