Java Code Examples for org.openqa.selenium.WebDriver#TargetLocator

The following examples show how to use org.openqa.selenium.WebDriver#TargetLocator . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChromeDriverEx.java    From HubTurbo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public WebDriver.TargetLocator switchTo() throws WebDriverException {
    if (!isTestChromeDriver) {
        return driver.switchTo();
    } else {
        // ~25% chance to throw an exception which is used to test resetBrowser
        if (Math.random() < 0.25) {
            throw new WebDriverException();
        }
    }
    return null;
}
 
Example 2
Source File: TargetedWebElementTest.java    From darcy-webdriver with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldCallGetRectOnUnderlyingWebElement() {
    WebDriver.TargetLocator locator = mock(WebDriver.TargetLocator.class);
    WebDriverTarget target = mock(WebDriverTarget.class);
    TargetedWebElement element = mock(TargetedWebElement.class);
    when(element.getRect()).thenReturn(mock(Rectangle.class));
    TargetedWebElement targetedWebElement = new TargetedWebElement(locator, target, element);

    targetedWebElement.getRect();
    verify(element).getRect();
}
 
Example 3
Source File: EventFiringWebDriverTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void alertEvents() {
  final WebDriver mockedDriver = mock(WebDriver.class);
  final Alert mockedAlert = mock(Alert.class);
  final WebDriver.TargetLocator mockedTargetLocator = mock(WebDriver.TargetLocator.class);

  when(mockedDriver.switchTo()).thenReturn(mockedTargetLocator);
  when(mockedTargetLocator.alert()).thenReturn(mockedAlert);

  WebDriverEventListener listener = mock(WebDriverEventListener.class);

  EventFiringWebDriver testedDriver = new EventFiringWebDriver(mockedDriver).register(listener);

  testedDriver.switchTo().alert().accept();
  testedDriver.switchTo().alert().dismiss();

  InOrder order = Mockito.inOrder(mockedDriver, mockedAlert, listener);
  order.verify(mockedDriver).switchTo();
  order.verify(listener).beforeAlertAccept(any(WebDriver.class));
  order.verify(mockedAlert).accept();
  order.verify(listener).afterAlertAccept(any(WebDriver.class));
  order.verify(mockedDriver).switchTo();
  order.verify(listener).beforeAlertDismiss(any(WebDriver.class));
  order.verify(mockedAlert).dismiss();
  order.verify(listener).afterAlertDismiss(any(WebDriver.class));
  verifyNoMoreInteractions(mockedDriver, mockedAlert, listener);
}
 
Example 4
Source File: ProxyFactory.java    From healenium-web with Apache License 2.0 4 votes vote down vote up
public static <T extends WebDriver.TargetLocator> T createTargetLocatorProxy(ClassLoader loader, InvocationHandler handler) {
    Class<?>[] interfaces = new Class[]{WebDriver.TargetLocator.class};
    return (T) Proxy.newProxyInstance(loader, interfaces, handler);
}
 
Example 5
Source File: BaseHandler.java    From healenium-web with Apache License 2.0 4 votes vote down vote up
protected WebDriver.TargetLocator wrapTarget(WebDriver.TargetLocator locator, ClassLoader loader) {
    TargetLocatorProxyInvocationHandler handler = new TargetLocatorProxyInvocationHandler(locator, engine);
    return ProxyFactory.createTargetLocatorProxy(loader, handler);
}
 
Example 6
Source File: SeleniumHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 4 votes vote down vote up
private WebDriver.TargetLocator getTargetLocator() {
    return driver().switchTo();
}
 
Example 7
Source File: ForwardingTargetedAlert.java    From darcy-webdriver with GNU General Public License v3.0 4 votes vote down vote up
public ForwardingTargetedAlert(WebDriver.TargetLocator locator) {
    this.locator = locator;
}