Search in sources :

Example 11 with WebUIDriver

use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.

the class UiElement method getDriver.

public CustomEventFiringWebDriver getDriver() {
    WebUIDriver uiDriver = WebUIDriver.getWebUIDriver(false);
    if (uiDriver == null) {
        throw new ScenarioException("Driver has not already been created");
    }
    CustomEventFiringWebDriver driver = (CustomEventFiringWebDriver) uiDriver.getDriver();
    if (driver == null) {
        throw new ScenarioException("Driver has not already been created");
    }
    return driver;
}
Also used : WebUIDriver(com.seleniumtests.driver.WebUIDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 12 with WebUIDriver

use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.

the class PictureElement method move.

/**
 * Move to the center of the picture
 * @param element	The element to move to
 * @param coordX	x offset from the center of the element
 * @param coordY	y offset from the center of the element
 * @return
 */
private Actions move(WebElement element, int coordX, int coordY) {
    WebUIDriver uiDriver = isDriverCreated();
    if (SeleniumTestsContextManager.isWebTest()) {
        // more browsers will be added to this conditions once they are migrated to new composite actions
        if (uiDriver.getConfig().getBrowserType() == BrowserType.FIREFOX) {
            // issue #133: firefox moves to center of element in page
            coordX -= element.getSize().width / 2;
            coordY -= element.getSize().height / 2;
        } else if (uiDriver.getConfig().getBrowserType() == BrowserType.INTERNET_EXPLORER || uiDriver.getConfig().getBrowserType() == BrowserType.EDGE || (uiDriver.getConfig().getBrowserType() == BrowserType.CHROME && uiDriver.getConfig().getMajorBrowserVersion() >= 75)) {
            // issue #180: internet explorer moves to center of element in viewport
            // do not take into accoung pixel aspect ratio, because selenium element coordinates are calculated with zooming (element will always have the same size even if zooming is different)
            Dimension viewportDim = ((CustomEventFiringWebDriver) uiDriver.getDriver()).getViewPortDimensionWithoutScrollbar(false);
            coordX -= Math.min(element.getSize().width, viewportDim.width) / 2;
            coordY -= Math.min(element.getSize().height, viewportDim.height) / 2;
        }
    }
    return new Actions(uiDriver.getDriver()).moveToElement(element, coordX, coordY);
}
Also used : WebUIDriver(com.seleniumtests.driver.WebUIDriver) Actions(org.openqa.selenium.interactions.Actions) Dimension(org.openqa.selenium.Dimension)

Example 13 with WebUIDriver

use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.

the class ConnectorsTest method createGridHubMockWithNodeOK.

/**
 * Creates a mock for grid on http://localhost:4321
 *
 * PowerMockito.mockStatic(Unirest.class); should be called first
 * @throws Exception
 */
protected WebUIDriver createGridHubMockWithNodeOK() throws Exception {
    WebUIDriver uiDriver = createMockedWebDriver();
    createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "Console");
    createServerMock("GET", SeleniumRobotGridConnector.NODE_TASK_SERVLET, 200, "ABC");
    createServerMock("POST", SeleniumRobotGridConnector.NODE_TASK_SERVLET, 200, "ABC");
    createServerMock("GET", SeleniumRobotGridConnector.GUI_SERVLET, 200, "Gui");
    createServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 200, "{\"http://localhost:4321\": {" + "    \"busy\": false," + "    \"lastSessionStart\": \"never\"," + "    \"version\": \"4.6.0\"," + "    \"usedTestSlots\": 0,\n" + "    \"testSlots\": 1," + "    \"status\": \"ACTIVE\"" + "  }," + "  \"hub\": {" + "    \"version\": \"4.6.1\"," + "    \"status\": \"ACTIVE\"" + "  }," + "  \"success\": true" + "}");
    createJsonServerMock("GET", SeleniumRobotGridConnector.API_TEST_SESSSION, 200, // session not found
    "{" + "  \"msg\": \"Cannot find test slot running session 7ef50edc-ce51-40dd-98b6-0a369bff38b in the registry.\"," + "  \"success\": false" + "}", // session found
    "{" + "  \"inactivityTime\": 409," + "  \"internalKey\": \"fef800fc-941d-4f76-9590-711da6443e00\"," + "  \"msg\": \"slot found !\"," + "  \"proxyId\": \"http://localhost:4321\"," + "  \"session\": \"7ef50edc-ce51-40dd-98b6-0a369bff38b1\"," + "  \"success\": true" + "}");
    return uiDriver;
}
Also used : WebUIDriver(com.seleniumtests.driver.WebUIDriver)

Example 14 with WebUIDriver

use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.

the class TestSeleniumGridDriverFactory method testSessionNeverGet.

/**
 * issue #311: Check we do not restart a test when no node is available to handle the request
 * @param testContext
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSessionNeverGet(ITestContext testContext) throws Exception {
    try {
        SeleniumGridDriverFactory.setRetryTimeout(1);
        System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, SERVER_URL + "/wd/hub");
        WebUIDriver uiDriver = createMockedWebDriver();
        // grid is there but we cannot get any matching node
        createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "Console");
        createServerMock("GET", SeleniumRobotGridConnector.GUI_SERVLET, 200, "Gui");
        createServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 500, "{}");
        ReporterTest.executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.METHODS, new String[] { "testDriverShort" });
        // check the test is not retried when
        String logs = ReporterTest.readSeleniumRobotLogFile();
        Assert.assertFalse(logs.contains("Retrying 1 time"));
    } finally {
        SeleniumGridDriverFactory.setRetryTimeout(SeleniumGridDriverFactory.DEFAULT_RETRY_TIMEOUT);
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
    }
}
Also used : WebUIDriver(com.seleniumtests.driver.WebUIDriver) Test(org.testng.annotations.Test) ReporterTest(com.seleniumtests.it.reporter.ReporterTest) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with WebUIDriver

use of com.seleniumtests.driver.WebUIDriver in project seleniumRobot by bhecquet.

the class TestSeleniumGridDriverFactory method testSessionNotGetOnFirstTime.

/**
 * issue #287: check driver is recreated if session cannot be get
 * @param testContext
 * @throws Exception
 */
@Test(groups = { "it" })
public void testSessionNotGetOnFirstTime(ITestContext testContext) throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, SERVER_URL + "/wd/hub");
        WebUIDriver uiDriver = createGridHubMockWithNodeOK();
        ReporterTest.executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForDriverTest" }, ParallelMode.METHODS, new String[] { "testDriverShort" });
        // check that we tried to create the driver once (we should have retried driver creation on grid inside 'createWebDriver' call)
        verify(uiDriver, times(1)).createWebDriver();
        String logs = ReporterTest.readSeleniumRobotLogFile();
        // driver is really created once, but, from WebUIDriver point of view, there was only one call
        Assert.assertEquals(StringUtils.countMatches(logs, "Start creating *chrome driver"), 1);
        // check error on first creation is displayed
        Assert.assertTrue(logs.contains("Cannot find test slot running session 7ef50edc-ce51-40dd-98b6-0a369bff38b"));
    } finally {
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
    }
}
Also used : WebUIDriver(com.seleniumtests.driver.WebUIDriver) Test(org.testng.annotations.Test) ReporterTest(com.seleniumtests.it.reporter.ReporterTest) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

WebUIDriver (com.seleniumtests.driver.WebUIDriver)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Test (org.testng.annotations.Test)19 GenericTest (com.seleniumtests.GenericTest)14 MockitoTest (com.seleniumtests.MockitoTest)14 ConnectorsTest (com.seleniumtests.ConnectorsTest)5 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)5 ReporterTest (com.seleniumtests.it.reporter.ReporterTest)5 NLWebDriver (com.neotys.selenium.proxies.NLWebDriver)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)2 VideoRecorder (com.seleniumtests.util.video.VideoRecorder)2 File (java.io.File)2 Dimension (org.openqa.selenium.Dimension)2 WebDriver (org.openqa.selenium.WebDriver)2 Point (org.openqa.selenium.Point)1 WebDriverException (org.openqa.selenium.WebDriverException)1 Actions (org.openqa.selenium.interactions.Actions)1 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)1 SessionId (org.openqa.selenium.remote.SessionId)1