Search in sources :

Example 16 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method clickMouse.

@ReplayOnError(waitAfterAction = true)
public void clickMouse() {
    Rectangle viewportPosition = detectViewPortPosition();
    // always scroll to element so that we can click on it with mouse
    setScrollToElementBeforeAction(true);
    findElement(true);
    outlineElement(getRealElementNoSearch());
    Rectangle elementRect = getRect();
    Point scrollPosition = ((CustomEventFiringWebDriver) getDriver()).getScrollPosition();
    CustomEventFiringWebDriver.leftClicOnDesktopAt(true, elementRect.x + elementRect.width / 2 + viewportPosition.x - scrollPosition.x, elementRect.y + elementRect.height / 2 + viewportPosition.y - scrollPosition.y, SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector());
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) Rectangle(org.openqa.selenium.Rectangle) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 17 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method simulateClick.

/**
 * Click with javascript
 */
@ReplayOnError(waitAfterAction = true)
public void simulateClick() {
    if (SeleniumTestsContextManager.isWebTest()) {
        ((CustomEventFiringWebDriver) updateDriver()).updateWindowsHandles();
    }
    findElement(true);
    outlineElement(getRealElementNoSearch());
    DriverConfig driverConfig = WebUIDriver.getWebUIDriver(false).getConfig();
    String mouseOverScript;
    if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
        mouseOverScript = "var event = new MouseEvent('mouseover', {view: window, bubbles: true, cancelable: true}) ; arguments[0].dispatchEvent(event);";
    } else {
        mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
    }
    executeScript(mouseOverScript, getRealElementNoSearch());
    WaitHelper.waitForSeconds(2);
    String clickScript = "";
    if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
        clickScript = "var event = new MouseEvent('click', {view: window, bubbles: true, cancelable: true}) ;" + "arguments[0].dispatchEvent(event);";
    } else {
        clickScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('click', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onclick');}";
    }
    executeScript(clickScript, getRealElementNoSearch());
    WaitHelper.waitForSeconds(2);
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) DriverConfig(com.seleniumtests.driver.DriverConfig) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 18 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method simulateDoubleClick.

@ReplayOnError(waitAfterAction = true)
public void simulateDoubleClick() {
    findElement(true);
    outlineElement(getRealElementNoSearch());
    DriverConfig driverConfig = WebUIDriver.getWebUIDriver(false).getConfig();
    String doubleClickScript;
    if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
        doubleClickScript = "var event = new MouseEvent('dblclick', {view: window, bubbles: true, cancelable: true}) ;" + "arguments[0].dispatchEvent(event);";
    } else {
        doubleClickScript = JS_CLICK_DOUBLE;
    }
    executeScript(doubleClickScript, getRealElementNoSearch());
}
Also used : DriverConfig(com.seleniumtests.driver.DriverConfig) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 19 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method simulateSendKeys.

@ReplayOnError(waitAfterAction = true)
public void simulateSendKeys(CharSequence... keysToSend) {
    findElement(true);
    // click on element before sending keys through keyboard
    getRealElementNoSearch().click();
    executeScript("arguments[0].focus();", getRealElementNoSearch());
    DriverConfig driverConfig = WebUIDriver.getWebUIDriver(false).getConfig();
    // sendKeysToActiveElement which are not available for firefox and IE
    if ((driverConfig.getBrowserType() == BrowserType.FIREFOX && FirefoxDriverFactory.isMarionetteMode()) || driverConfig.getBrowserType() == BrowserType.INTERNET_EXPLORER || driverConfig.getBrowserType() == BrowserType.EDGE || (driverConfig.getBrowserType() == BrowserType.CHROME && driverConfig.getMajorBrowserVersion() >= 75)) {
        logger.warn("using specific Marionette method");
        executeScript(String.format("arguments[0].value='%s';", keysToSend[0].toString()), getRealElementNoSearch());
    } else {
        // use keyboard to type
        ((CustomEventFiringWebDriver) getDriver()).getKeyboard().sendKeys(keysToSend);
    }
}
Also used : DriverConfig(com.seleniumtests.driver.DriverConfig) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 20 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method findHtmlElements.

/**
 * Find elements inside this element
 *
 * @param childBy
 * @return List of HtmlElement's based on real WebElement
 */
@ReplayOnError
public List<WebElement> findHtmlElements(By childBy) {
    // find the root element
    findElement(false, false);
    List<WebElement> htmlElements = new ArrayList<>();
    List<WebElement> elements = getRealElementNoSearch().findElements(childBy);
    // which retries search
    if (elements.isEmpty()) {
        throw new NoSuchElementException("No elements found for " + childBy.toString());
    }
    for (int i = 0; i < elements.size(); i++) {
        // frame set to null as we expect the frames are searched in the parent element
        htmlElements.add(new HtmlElement("", childBy, this, i));
    }
    return htmlElements;
}
Also used : ArrayList(java.util.ArrayList) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Aggregations

ReplayOnError (com.seleniumtests.uipage.ReplayOnError)24 Point (org.openqa.selenium.Point)11 WebElement (org.openqa.selenium.WebElement)7 PerformsTouchActions (io.appium.java_client.PerformsTouchActions)5 MobileElement (io.appium.java_client.MobileElement)4 ScenarioException (com.seleniumtests.customexception.ScenarioException)3 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)3 DriverConfig (com.seleniumtests.driver.DriverConfig)3 MultiTouchAction (io.appium.java_client.MultiTouchAction)3 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 NoSuchElementException (org.openqa.selenium.NoSuchElementException)3 Actions (org.openqa.selenium.interactions.Actions)2 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 InvalidElementStateException (org.openqa.selenium.InvalidElementStateException)1 Rectangle (org.openqa.selenium.Rectangle)1 TimeoutException (org.openqa.selenium.TimeoutException)1