|
47 | 47 | import org.openqa.selenium.Platform; |
48 | 48 | import org.openqa.selenium.Point; |
49 | 49 | import org.openqa.selenium.Rectangle; |
| 50 | +import org.openqa.selenium.SearchContext; |
50 | 51 | import org.openqa.selenium.SessionNotCreatedException; |
51 | 52 | import org.openqa.selenium.WebDriver; |
52 | 53 | import org.openqa.selenium.WebElement; |
@@ -293,6 +294,25 @@ public void canHandleFindElementW3CCommand() throws IOException { |
293 | 294 | "using", "id", "value", "cheese"))); |
294 | 295 | } |
295 | 296 |
|
| 297 | + @Test |
| 298 | + public void canHandleFindElementCommandWithNonStandardLocator() throws IOException { |
| 299 | + WebElement element1 = mock(WebElement.class); |
| 300 | + WebElement element2 = mock(WebElement.class); |
| 301 | + By locator = new By() { |
| 302 | + @Override |
| 303 | + public List<WebElement> findElements(SearchContext context) { |
| 304 | + return Arrays.asList(element1, element2); |
| 305 | + } |
| 306 | + }; |
| 307 | + CommandExecutor executor = prepareExecutorMock(echoCapabilities); |
| 308 | + |
| 309 | + RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities()); |
| 310 | + WebElement found = driver.findElement(locator); |
| 311 | + |
| 312 | + assertThat(found).isSameAs(element1); |
| 313 | + verifyCommands(executor, driver.getSessionId()); |
| 314 | + } |
| 315 | + |
296 | 316 | @Test |
297 | 317 | public void canHandleFindElementsOSSCommand() throws IOException { |
298 | 318 | CommandExecutor executor = prepareExecutorMock( |
@@ -329,6 +349,25 @@ public void canHandleFindElementsW3CCommand() throws IOException { |
329 | 349 | "using", "id", "value", "cheese"))); |
330 | 350 | } |
331 | 351 |
|
| 352 | + @Test |
| 353 | + public void canHandleFindElementsCommandWithNonStandardLocator() throws IOException { |
| 354 | + WebElement element1 = mock(WebElement.class); |
| 355 | + WebElement element2 = mock(WebElement.class); |
| 356 | + By locator = new By() { |
| 357 | + @Override |
| 358 | + public List<WebElement> findElements(SearchContext context) { |
| 359 | + return Arrays.asList(element1, element2); |
| 360 | + } |
| 361 | + }; |
| 362 | + CommandExecutor executor = prepareExecutorMock(echoCapabilities); |
| 363 | + |
| 364 | + RemoteWebDriver driver = new RemoteWebDriver(executor, new ImmutableCapabilities()); |
| 365 | + List<WebElement> found = driver.findElements(locator); |
| 366 | + |
| 367 | + assertThat(found).containsExactly(element1, element2); |
| 368 | + verifyCommands(executor, driver.getSessionId()); |
| 369 | + } |
| 370 | + |
332 | 371 | @Test |
333 | 372 | public void returnsEmptyListIfRemoteEndReturnsNullFromFindElements() { |
334 | 373 | CommandExecutor executor = prepareExecutorMock(echoCapabilities, nullValueResponder); |
|
0 commit comments