Search in sources :

Example 1 with Interaction

use of org.openqa.selenium.interactions.Interaction in project flue2ent by DefinityLabs.

the class ActionsPluginTest method tick_withInteraction_callsTick.

@Test
public void tick_withInteraction_callsTick() throws Exception {
    Interaction interaction = mock(Interaction.class);
    ActionsPlugin actionsPlugin = new ActionsPlugin(driver);
    actionsPlugin.tick(interaction);
    verify(actions).tick(interaction);
}
Also used : Interaction(org.openqa.selenium.interactions.Interaction) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Interaction

use of org.openqa.selenium.interactions.Interaction in project myfaces-tobago by apache.

the class FrontendTest method frontendTest.

/**
 * Call every page with a specific *.test.js.
 */
@ParameterizedTest
@MethodSource("standardTestProvider")
void frontendTest(String path, int testNumber, int testSize) throws MalformedURLException, UnknownHostException, UnsupportedEncodingException {
    final String timeLeft = getTimeLeft(FrontendTest.startTime, testSize, testNumber);
    LOG.info("(" + testNumber + "/" + testSize + " | time left: " + timeLeft + ") - path: " + path);
    final String base = path.substring(0, path.length() - 6);
    final String url = getTomcatUrl() + "/test.xhtml?base=" + URLEncoder.encode(base, "UTF-8");
    WebDriver webDriver = getWebDriver();
    webDriver.get(url);
    // move the mouse cursor away to avoid issues with CSS :hover event
    Actions actions = new Actions(webDriver);
    PointerInput pointerInput = new PointerInput(PointerInput.Kind.MOUSE, "default mouse");
    Interaction interaction = pointerInput.createPointerMove(Duration.ZERO, PointerInput.Origin.pointer(), 1, 1);
    actions.tick(interaction).build().perform();
    List<WebElement> results = getJasmineResults(webDriver, path);
    parseJasmineResults(results, path);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Actions(org.openqa.selenium.interactions.Actions) Interaction(org.openqa.selenium.interactions.Interaction) WebElement(org.openqa.selenium.WebElement) PointerInput(org.openqa.selenium.interactions.PointerInput) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with Interaction

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

the class CompositeActions method updateWindowHandles.

/**
 * Analyse action list and determine if a clic action occured. If it's the case, update window handles
 * @param actionsList
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private void updateWindowHandles(LinkedList<Interaction> actionsList) throws NoSuchFieldException, IllegalAccessException {
    Boolean clic = null;
    boolean clickRequested = false;
    for (Interaction action : actionsList) {
        if (action.getClass().getName().contains("PointerInput$PointerPress")) {
            Field buttonField = action.getClass().getDeclaredField("button");
            buttonField.setAccessible(true);
            int button = buttonField.getInt(action);
            Field directionField = action.getClass().getDeclaredField("direction");
            directionField.setAccessible(true);
            String direction = directionField.get(action).toString();
            // only left button
            if (button != 0) {
                clic = null;
                continue;
            }
            // check we have a DOWN -> UP sequence
            if ("DOWN".equals(direction) && clic == null) {
                clic = true;
            } else if (Boolean.TRUE.equals(clic) && "UP".equals(direction)) {
                clic = null;
                clickRequested = true;
            } else {
                clic = null;
            }
        } else {
            clic = null;
        }
    }
    if (clickRequested) {
        ((CustomEventFiringWebDriver) WebUIDriver.getWebDriver(false)).updateWindowsHandles();
    }
}
Also used : Field(java.lang.reflect.Field) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Interaction(org.openqa.selenium.interactions.Interaction) JoinPoint(org.aspectj.lang.JoinPoint)

Example 4 with Interaction

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

the class CompositeActions method updateHandlesNewActions.

/**
 * Intercept calls to {@link org.openqa.selenium.remote.RemoteWebDriver.perform(Collection<Sequence> actions)} method which handles
 * the new way of sending composite actions
 * @param joinPoint
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 */
@Before("execution(public void org.openqa.selenium.remote.RemoteWebDriver.perform (..))")
public void updateHandlesNewActions(JoinPoint joinPoint) throws NoSuchFieldException, IllegalAccessException {
    @SuppressWarnings("unchecked") Collection<Sequence> sequences = (Collection<Sequence>) joinPoint.getArgs()[0];
    for (Sequence sequence : sequences) {
        Field actionsField = Sequence.class.getDeclaredField("actions");
        actionsField.setAccessible(true);
        @SuppressWarnings("unchecked") LinkedList<Interaction> actionsList = (LinkedList<Interaction>) actionsField.get(sequence);
        updateWindowHandles(actionsList);
    }
}
Also used : Field(java.lang.reflect.Field) Interaction(org.openqa.selenium.interactions.Interaction) Collection(java.util.Collection) Sequence(org.openqa.selenium.interactions.Sequence) LinkedList(java.util.LinkedList) Before(org.aspectj.lang.annotation.Before)

Example 5 with Interaction

use of org.openqa.selenium.interactions.Interaction 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

Interaction (org.openqa.selenium.interactions.Interaction)5 Field (java.lang.reflect.Field)3 LinkedList (java.util.LinkedList)2 PointerInput (org.openqa.selenium.interactions.PointerInput)2 Sequence (org.openqa.selenium.interactions.Sequence)2 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)1 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JoinPoint (org.aspectj.lang.JoinPoint)1 Before (org.aspectj.lang.annotation.Before)1 Test (org.junit.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 WebDriver (org.openqa.selenium.WebDriver)1 WebElement (org.openqa.selenium.WebElement)1 Actions (org.openqa.selenium.interactions.Actions)1 InputSource (org.openqa.selenium.interactions.InputSource)1 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)1