Search in sources :

Example 6 with SeleniumRobotGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector 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 7 with SeleniumRobotGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector 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 8 with SeleniumRobotGridConnector

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

the class TestSeleniumRobotGridConnector method initConnector.

@BeforeMethod(groups = { "it" })
public void initConnector(ITestContext ctx) {
    initThreadContext(ctx);
    connector = new SeleniumRobotGridConnector("http://localhost:4444/wd/hub");
    if (!connector.isGridActive()) {
        throw new SkipException("no seleniumrobot grid available");
    }
    connector.setNodeUrl("http://localhost:5555");
    gridLogger = spy(connector.getLogger());
}
Also used : SeleniumRobotGridConnector(com.seleniumtests.connectors.selenium.SeleniumRobotGridConnector) SkipException(org.testng.SkipException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with SeleniumRobotGridConnector

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

the class TestSeleniumRobotGridConnector method testIsGridActiveWithRobotGridActiveInvalidStatus.

/**
 * Check that we get false if the status returned by grid is invalid (no JSON)
 * @throws ClientProtocolException
 * @throws IOException
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testIsGridActiveWithRobotGridActiveInvalidStatus() throws ClientProtocolException, IOException {
    String hubStatus = "null";
    SeleniumGridConnector connector = new SeleniumRobotGridConnector(SERVER_URL);
    createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 200, "some text");
    createServerMock("GET", SeleniumRobotGridConnector.STATUS_SERVLET, 200, 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 10 with SeleniumRobotGridConnector

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

the class TestSeleniumRobotGridConnector method testIsGridActiveWithGridNotPresent.

@Test(groups = { "ut" })
public void testIsGridActiveWithGridNotPresent() throws ClientProtocolException, IOException {
    SeleniumGridConnector connector = new SeleniumRobotGridConnector(SERVER_URL);
    when(Unirest.get(SERVER_URL + SeleniumGridConnector.CONSOLE_SERVLET)).thenReturn(getRequest);
    when(getRequest.asString()).thenThrow(UnirestException.class);
    Assert.assertFalse(connector.isGridActive());
}
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)

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