Search in sources :

Example 1 with InputSource

use of org.openqa.selenium.interactions.InputSource in project seleniumRobot by bhecquet.

the class ReplayAction method updateScrollFlagForElement.

/**
 * Updates the scrollToelementBeforeAction flag of HtmlElement for CompositeActions
 * Therefore, it looks at origin field of PointerInput$Move CompositeAction and update the flag
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
private void updateScrollFlagForElement(ProceedingJoinPoint joinPoint, Boolean forcedValue, WebDriverException parentException) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Object actions = joinPoint.getTarget();
    // Only the later case is covered here
    if (!actions.getClass().toString().contains("BuiltAction")) {
        return;
    }
    Field sequencesField = actions.getClass().getDeclaredField("sequences");
    sequencesField.setAccessible(true);
    Map<InputSource, Sequence> sequences = (Map<InputSource, Sequence>) sequencesField.get(actions);
    for (Sequence sequence : sequences.values()) {
        Field actionsField = Sequence.class.getDeclaredField("actions");
        actionsField.setAccessible(true);
        LinkedList<Interaction> actionsList = (LinkedList<Interaction>) actionsField.get(sequence);
        for (Interaction action : actionsList) {
            if (action.getClass().getName().contains("PointerInput$Move")) {
                Field originField = action.getClass().getDeclaredField("origin");
                originField.setAccessible(true);
                try {
                    PointerInput.Origin origin = (PointerInput.Origin) originField.get(action);
                    // so that it can be treated elsewhere (mainly inside replayHtmlElement())
                    if (origin.asArg() instanceof HtmlElement) {
                        HtmlElement element = (HtmlElement) origin.asArg();
                        if (forcedValue == null) {
                            if (element.isScrollToElementBeforeAction()) {
                                element.setScrollToElementBeforeAction(false);
                            } else {
                                element.setScrollToElementBeforeAction(true);
                            }
                        } else {
                            element.setScrollToElementBeforeAction(forcedValue);
                        }
                    } else if (origin.asArg() instanceof RemoteWebElement && parentException != null) {
                        throw parentException;
                    }
                } catch (ClassCastException e1) {
                // nothing
                }
            }
        }
    }
}
Also used : InputSource(org.openqa.selenium.interactions.InputSource) Interaction(org.openqa.selenium.interactions.Interaction) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Sequence(org.openqa.selenium.interactions.Sequence) LinkedList(java.util.LinkedList) Field(java.lang.reflect.Field) HashMap(java.util.HashMap) Map(java.util.Map) PointerInput(org.openqa.selenium.interactions.PointerInput)

Aggregations

HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 InputSource (org.openqa.selenium.interactions.InputSource)1 Interaction (org.openqa.selenium.interactions.Interaction)1 PointerInput (org.openqa.selenium.interactions.PointerInput)1 Sequence (org.openqa.selenium.interactions.Sequence)1 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)1