Search in sources :

Example 1 with PointerInput

use of org.openqa.selenium.interactions.PointerInput 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 2 with PointerInput

use of org.openqa.selenium.interactions.PointerInput 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)2 PointerInput (org.openqa.selenium.interactions.PointerInput)2 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 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 Sequence (org.openqa.selenium.interactions.Sequence)1 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)1