Search in sources :

Example 6 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.

the class TestTestTasks method testExecuteCommandGrid.

@Test(groups = { "ut" })
public void testExecuteCommandGrid(final ITestContext testNGCtx) {
    SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://localhost:4444/hub/wd"));
    gridConnector.setNodeUrl("http://localhost:5555/hub/wd");
    doReturn("hello guys").when(gridConnector).executeCommand("echo", -1, "hello");
    // grid connector is in use only if session Id exists
    doReturn(new SessionId("1234")).when(gridConnector).getSessionId();
    PowerMockito.mockStatic(SeleniumGridConnectorFactory.class);
    PowerMockito.when(SeleniumGridConnectorFactory.getInstances(Arrays.asList("http://localhost:4444/hub/wd"))).thenReturn(Arrays.asList(gridConnector));
    try {
        System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, "http://localhost:4444/hub/wd");
        initThreadContext(testNGCtx);
        SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnectors();
        String response = TestTasks.executeCommand("echo", "hello");
        Assert.assertEquals(response, "hello guys");
    } finally {
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
    }
}
Also used : SeleniumRobotGridConnector(com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) SessionId(org.openqa.selenium.remote.SessionId) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 7 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.

the class TestTestTasks method testKillProcessGrid.

@Test(groups = { "ut" })
public void testKillProcessGrid(final ITestContext testNGCtx) {
    SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://localhost:4444/hub/wd"));
    doNothing().when(gridConnector).killProcess("some_process");
    // grid connector is in use only if session Id exists
    doReturn(new SessionId("1234")).when(gridConnector).getSessionId();
    PowerMockito.mockStatic(SeleniumGridConnectorFactory.class);
    PowerMockito.when(SeleniumGridConnectorFactory.getInstances(Arrays.asList("http://localhost:4444/hub/wd"))).thenReturn(Arrays.asList(gridConnector));
    try {
        System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, "http://localhost:4444/hub/wd");
        initThreadContext(testNGCtx);
        SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnectors();
        TestTasks.killProcess("some_process");
        verify(gridConnector).killProcess("some_process");
    } finally {
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
    }
}
Also used : SeleniumRobotGridConnector(com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) SessionId(org.openqa.selenium.remote.SessionId) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 8 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.

the class TestTestTasks method testGetProcessListGridNotUsed.

/**
 * Test when the grid connector is not initialized
 * When grid connector does not return any sessionId, it's not active
 * @param testNGCtx
 */
@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testGetProcessListGridNotUsed(final ITestContext testNGCtx) {
    SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://localhost:4444/hub/wd"));
    doReturn(Arrays.asList(10, 20)).when(gridConnector).getProcessList("some_process");
    PowerMockito.mockStatic(SeleniumGridConnectorFactory.class);
    PowerMockito.when(SeleniumGridConnectorFactory.getInstances(Arrays.asList("http://localhost:4444/hub/wd"))).thenReturn(Arrays.asList(gridConnector));
    try {
        System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, "http://localhost:4444/hub/wd");
        initThreadContext(testNGCtx);
        SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnectors();
        TestTasks.getProcessList("some_process");
        verify(gridConnector).getProcessList("some_process");
    } finally {
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
    }
}
Also used : SeleniumRobotGridConnector(com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 9 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.

the class SeleniumGridDriverFactory method createWebDriver.

@Override
public WebDriver createWebDriver() {
    // create capabilities, specific to OS
    MutableCapabilities capabilities = createSpecificGridCapabilities(webDriverConfig);
    capabilities.merge(driverOptions);
    // upload file on all available grids as we don't know which one will be chosen before driver has been created
    for (SeleniumGridConnector gridConnector : gridConnectors) {
        gridConnector.uploadMobileApp(capabilities);
    }
    // connection to grid is made here
    for (int i = 0; i < 3; i++) {
        long start = new Date().getTime();
        driver = getDriver(capabilities);
        long duration = new Date().getTime() - start;
        setImplicitWaitTimeout(webDriverConfig.getImplicitWaitTimeout());
        if (webDriverConfig.getPageLoadTimeout() >= 0 && SeleniumTestsContextManager.isWebTest()) {
            setPageLoadTimeout(webDriverConfig.getPageLoadTimeout());
        }
        this.setWebDriver(driver);
        // if session has not been really created, we retry
        try {
            activeGridConnector.getSessionInformationFromGrid((RemoteWebDriver) driver, duration);
        } catch (SessionNotCreatedException e) {
            logger.error(e.getMessage());
            continue;
        }
        // sets a file detector. This is only useful for remote drivers
        ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
        // create a BrowserInfo based on information get from grid hub
        selectedBrowserInfo = new BrowserInfo(BrowserType.getBrowserTypeFromSeleniumBrowserType(((RemoteWebDriver) driver).getCapabilities().getBrowserName()), ((RemoteWebDriver) driver).getCapabilities().getVersion());
        return driver;
    }
    throw new SessionNotCreatedException("Session not created on any grid hub, after 3 tries");
}
Also used : LocalFileDetector(org.openqa.selenium.remote.LocalFileDetector) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) MutableCapabilities(org.openqa.selenium.MutableCapabilities) SessionNotCreatedException(org.openqa.selenium.SessionNotCreatedException) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Date(java.util.Date)

Example 10 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector in project seleniumRobot by bhecquet.

the class TestSeleniumGridConnector method testDoNothing.

/**
 * With simple selenium grid, upload is not available
 * @throws ClientProtocolException
 * @throws UnsupportedOperationException
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testDoNothing() throws ClientProtocolException, IOException {
    SeleniumGridConnector connector = new SeleniumGridConnector("http://localhost:6666");
    connector.uploadMobileApp(new DesiredCapabilities());
    verify(client, never()).execute((HttpHost) any(HttpHost.class), any(HttpRequest.class));
}
Also used : HttpRequest(org.apache.http.HttpRequest) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SeleniumGridConnector (com.seleniumtests.connectors.selenium.SeleniumGridConnector)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)28 Test (org.testng.annotations.Test)28 SeleniumRobotGridConnector (com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector)19 ConnectorsTest (com.seleniumtests.ConnectorsTest)18 GenericTest (com.seleniumtests.GenericTest)13 XmlTest (org.testng.xml.XmlTest)13 MockitoTest (com.seleniumtests.MockitoTest)10 SessionId (org.openqa.selenium.remote.SessionId)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ScenarioException (com.seleniumtests.customexception.ScenarioException)3 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)3 ITestResult (org.testng.ITestResult)3 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 InputStream (java.io.InputStream)2 StringInputStream (org.apache.tools.ant.filters.StringInputStream)2 SessionNotCreatedException (org.openqa.selenium.SessionNotCreatedException)2 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)2 SeleniumGridNodeNotAvailable (com.seleniumtests.customexception.SeleniumGridNodeNotAvailable)1 SeleniumRobotLogger (com.seleniumtests.util.logging.SeleniumRobotLogger)1