Search in sources :

Example 16 with SeleniumRobotGridConnector

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

the class TestSeleniumRobotGridConnector method testIsGridActiveWithRobotGridReplyInError.

/**
 * Check that we get false if the server returns code != 200
 * @throws ClientProtocolException
 * @throws IOException
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testIsGridActiveWithRobotGridReplyInError() throws ClientProtocolException, IOException {
    String hubStatus = "Internal Server Error";
    SeleniumGridConnector connector = new SeleniumRobotGridConnector(SERVER_URL);
    createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "some text");
    createServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 500, hubStatus);
    Assert.assertFalse(connector.isGridActive());
}
Also used : SeleniumRobotGridConnector(com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with SeleniumRobotGridConnector

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

the class TestSeleniumRobotGridConnector method testExecuteCommandWithoutNodeUrl.

/**
 * Test executing command when node is still unknown (driver not initialized). In this case, ScenarioException must be thrown
 * @throws UnsupportedOperationException
 * @throws IOException
 * @throws UnirestException
 */
@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testExecuteCommandWithoutNodeUrl() throws UnsupportedOperationException, IOException {
    createServerMock("POST", SeleniumRobotGridConnector.NODE_TASK_SERVLET, 200, "foo");
    SeleniumGridConnector connector = new SeleniumRobotGridConnector("http://localhost:4444/wd/hub");
    connector.executeCommand("myProcess", "arg1");
}
Also used : SeleniumRobotGridConnector(com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with SeleniumRobotGridConnector

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

the class TestSeleniumRobotGridConnector method testIsGridActiveWithRobotGridActive.

/**
 * Check that we get true if the grid is ACTIVE and at least one node is present
 * @throws ClientProtocolException
 * @throws IOException
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testIsGridActiveWithRobotGridActive() throws ClientProtocolException, IOException {
    String hubStatus = "{" + "\"http:\\u002f\\u002fnode1.company.com:5555\": {\r\n" + "    \"busy\": false,\r\n" + "    \"lastSessionStart\": \"2018-08-31T08:30:06Z\",\r\n" + "    \"version\": \"3.14.0\",\r\n" + "    \"usedTestSlots\": 0,\r\n" + "    \"testSlots\": 1,\r\n" + "    \"status\": \"ACTIVE\"\r\n" + "  },\r\n" + "  \"hub\": {\r\n" + "    \"version\": \"3.14.0\",\r\n" + "    \"status\": \"ACTIVE\"\r\n" + "  },\r\n" + "  \"success\": true\r\n" + "}";
    SeleniumGridConnector connector = new SeleniumRobotGridConnector(SERVER_URL);
    createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "some text");
    createServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 200, hubStatus);
    Assert.assertTrue(connector.isGridActive());
}
Also used : SeleniumRobotGridConnector(com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with SeleniumRobotGridConnector

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

the class TestTestTasks method testExecuteCommandOtherRunMode.

/**
 * Test kill process is not called when not using local or grid mode
 * @param testNGCtx
 */
@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testExecuteCommandOtherRunMode(final ITestContext testNGCtx) {
    SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://saucelabs:4444/hub/wd"));
    PowerMockito.mockStatic(SeleniumGridConnectorFactory.class);
    PowerMockito.when(SeleniumGridConnectorFactory.getInstances(Arrays.asList("http://saucelabs:4444/hub/wd"))).thenReturn(Arrays.asList(gridConnector));
    try {
        System.setProperty(SeleniumTestsContext.RUN_MODE, "saucelabs");
        System.setProperty(SeleniumTestsContext.PLATFORM, "windows");
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, "http://saucelabs:4444/hub/wd");
        initThreadContext(testNGCtx);
        TestTasks.executeCommand("echo", "hello");
    } finally {
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.PLATFORM);
        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 20 with SeleniumRobotGridConnector

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

the class TestTestTasks method testGetProcessListGrid.

@Test(groups = { "ut" })
public void testGetProcessListGrid(final ITestContext testNGCtx) {
    SeleniumGridConnector gridConnector = spy(new SeleniumRobotGridConnector("http://localhost:4444/hub/wd"));
    doReturn(Arrays.asList(10, 20)).when(gridConnector).getProcessList("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.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) 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)

Aggregations

SeleniumRobotGridConnector (com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector)21 SeleniumGridConnector (com.seleniumtests.connectors.selenium.SeleniumGridConnector)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Test (org.testng.annotations.Test)19 GenericTest (com.seleniumtests.GenericTest)10 MockitoTest (com.seleniumtests.MockitoTest)10 XmlTest (org.testng.xml.XmlTest)10 ConnectorsTest (com.seleniumtests.ConnectorsTest)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 SessionId (org.openqa.selenium.remote.SessionId)6 BeforeMethod (org.testng.annotations.BeforeMethod)2 HttpRequestWithBody (kong.unirest.HttpRequestWithBody)1 SkipException (org.testng.SkipException)1