org.openqa.selenium.interactions.Interactive Java Examples

The following examples show how to use org.openqa.selenium.interactions.Interactive. 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: DragAndDropStepsTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void shouldDragAndDropToTargetAtLocation()
{
    WebElement draggable = mockWebElementWithRect(100, 100, 50, 50);
    WebElement target = mockWebElementWithRect(200, 200, 50, 50);
    WebDriver driver = mock(WebDriver.class, withSettings().extraInterfaces(Interactive.class));
    when(webDriverProvider.get()).thenReturn(driver);
    testDragAndDropToTargetAtLocation(draggable, Location.TOP, target);
    String actionsSequence = String.format(
            "{id=default mouse, type=pointer, parameters={pointerType=mouse}, "
            + "actions=["
            + "{duration=100, x=0, y=0, type=pointerMove, origin=Mock for WebElement, hashCode: %s}, "
            + "{button=0, type=pointerDown}, "
            + "{duration=200, x=10, y=0, type=pointerMove, origin=pointer}, "
            + "{duration=200, x=-10, y=0, type=pointerMove, origin=pointer}, "
            + "{duration=200, x=100, y=50, type=pointerMove, origin=pointer}, "
            + "{button=0, type=pointerUp}, "
            + "{duration=1000, type=pause}]}", draggable.hashCode());
    verify((Interactive) driver).perform(
            argThat(arg -> arg.iterator().next().encode().toString().equals(actionsSequence)));
}
 
Example #2
Source File: DelegatingWebDriver.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Override
public void perform(Collection<Sequence> actions)
{
    if (wrappedDriver instanceof Interactive)
    {
        ((Interactive) wrappedDriver).perform(actions);
        return;
    }
    throw new UnsupportedOperationException(ADVANCED_INTERACTION_NOT_SUPPORTED);
}
 
Example #3
Source File: DelegatingWebDriver.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Override
public void resetInputState()
{
    if (wrappedDriver instanceof Interactive)
    {
        ((Interactive) wrappedDriver).resetInputState();
        return;
    }
    throw new UnsupportedOperationException(ADVANCED_INTERACTION_NOT_SUPPORTED);
}
 
Example #4
Source File: DelegatingWebDriverTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testPerform()
{
    WebDriver interactiveDriver = Mockito.mock(WebDriver.class, withSettings().extraInterfaces(Interactive.class));
    DelegatingWebDriver interactiveDelegatingDriver = new DelegatingWebDriver(interactiveDriver);
    interactiveDelegatingDriver.perform(List.of());
    verify((Interactive) interactiveDriver).perform(List.of());
}
 
Example #5
Source File: DelegatingWebDriverTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testResetInputState()
{
    WebDriver interactiveDriver = Mockito.mock(WebDriver.class, withSettings().extraInterfaces(Interactive.class));
    DelegatingWebDriver interactiveDelegatingDriver = new DelegatingWebDriver(interactiveDriver);
    interactiveDelegatingDriver.resetInputState();
    verify((Interactive) interactiveDriver).resetInputState();
}
 
Example #6
Source File: ActionStepsTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testExecuteActionsSequenceElementIsNull()
{
    SearchAttributes searchAttributes = new SearchAttributes(ActionAttributeType.XPATH, SIGNATURE_FIELD_XPATH);

    when(baseValidations.assertIfElementExists(ELEMENT_EXISTS_MESSAGE, searchAttributes)).thenReturn(null);

    List<SequenceAction> actions = List.of(
            new SequenceAction(SequenceActionType.DOUBLE_CLICK, searchAttributes),
            new SequenceAction(SequenceActionType.ENTER_TEXT, TEXT)
            );
    actionSteps.executeSequenceOfActions(actions);
    verify((Interactive) webDriver, never()).perform(any());
}
 
Example #7
Source File: ProxyFactory.java    From healenium-web with Apache License 2.0 5 votes vote down vote up
public static <T extends WebDriver> SelfHealingDriver createDriverProxy(ClassLoader loader, InvocationHandler handler, Class<T> clazz) {
    Class<?>[] interfaces = Stream.concat(
        Arrays.stream(clazz.getInterfaces()),
        Stream.of(JavascriptExecutor.class, SelfHealingDriver.class, HasInputDevices.class, Interactive.class)
    ).distinct().toArray(Class[]::new);

    return (SelfHealingDriver) Proxy.newProxyInstance(loader, interfaces, handler);
}
 
Example #8
Source File: EventFiringWebDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public void perform(Collection<Sequence> actions) {
  if (driver instanceof Interactive) {
    ((Interactive) driver).perform(actions);
    return;
  }
  throw new UnsupportedOperationException("Underlying driver does not implement advanced"
                                          + " user interactions yet.");

}
 
Example #9
Source File: EventFiringWebDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public void resetInputState() {
  if (driver instanceof Interactive) {
    ((Interactive) driver).resetInputState();
    return;
  }
  throw new UnsupportedOperationException("Underlying driver does not implement advanced"
                                          + " user interactions yet.");

}
 
Example #10
Source File: ActionStepsTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("LineLength")
@Test
void testExecuteSequenceOfActions()
{
    SearchAttributes searchAttributes = new SearchAttributes(ActionAttributeType.XPATH, SIGNATURE_FIELD_XPATH);
    Point point = mock(Point.class);
    WebElement webElement = mock(WebElement.class);
    int offset = 15;

    when(baseValidations.assertIfElementExists(ELEMENT_EXISTS_MESSAGE, searchAttributes)).thenReturn(webElement);
    when(point.getX()).thenReturn(offset);
    when(point.getY()).thenReturn(offset);

    List<SequenceAction> actions = List.of(
            new SequenceAction(SequenceActionType.DOUBLE_CLICK, searchAttributes),
            new SequenceAction(SequenceActionType.CLICK_AND_HOLD, searchAttributes),
            new SequenceAction(SequenceActionType.MOVE_BY_OFFSET, point),
            new SequenceAction(SequenceActionType.RELEASE, searchAttributes),
            new SequenceAction(SequenceActionType.ENTER_TEXT, TEXT),
            new SequenceAction(SequenceActionType.CLICK, searchAttributes),
            new SequenceAction(SequenceActionType.MOVE_TO, searchAttributes),
            new SequenceAction(SequenceActionType.DOUBLE_CLICK, null),
            new SequenceAction(SequenceActionType.CLICK_AND_HOLD, null),
            new SequenceAction(SequenceActionType.RELEASE, null),
            new SequenceAction(SequenceActionType.CLICK, null)
            );
    actionSteps.executeSequenceOfActions(actions);
    verify((Interactive) webDriver).perform(argThat(arg -> {
        int hash = webElement.hashCode();
        String mouseSequence = "{id=default mouse, type=pointer, parameters={pointerType=mouse}, actions=["
                + format(POINTER_MOVE, hash)
                + DOUBLE_CLICK_ACTION + SEPARATOR
                + format(POINTER_MOVE, hash)
                + CLICK_AND_HOLD_ACTION + SEPARATOR
                + "{duration=200, x=15, y=15, type=pointerMove, origin=pointer}" + SEPARATOR
                + format(POINTER_MOVE, hash)
                + RELEASE_ACTION + SEPARATOR
                + DURATION_PART + DURATION_PART
                + format(POINTER_MOVE, hash)
                + CLICK_ACTION + SEPARATOR
                + format(POINTER_MOVE_ACTION, hash) + SEPARATOR
                + DOUBLE_CLICK_ACTION + SEPARATOR
                + CLICK_AND_HOLD_ACTION + SEPARATOR
                + RELEASE_ACTION + SEPARATOR
                + CLICK_ACTION
                + "]}";
        String keyboardSequence = "{type=key, actions=["
                + DURATION_PART + DURATION_PART
                + "{duration=0, type=pause}, {duration=0, type=pause}, "
                + "{type=keyDown, value=t}, {type=keyUp, value=t}, {type=keyDown, value=e}, {type=keyUp, value=e}, "
                + "{type=keyDown, value=x}, {type=keyUp, value=x}, {type=keyDown, value=t}, {type=keyUp, value=t}, "
                + "{duration=0, type=pause}, {duration=0, type=pause}, {duration=0, type=pause}, {duration=0, type=pause},"
                + " {duration=0, type=pause}, {duration=0, type=pause}, {duration=0, type=pause}, {duration=0, type=pause},"
                + " {duration=0, type=pause}, {duration=0, type=pause}, {duration=0, type=pause}, {duration=0, type=pause}], "
                + "id=default keyboard}";
        return asString(arg).equals(mouseSequence + keyboardSequence);
    }));
}