Search in sources :

Example 21 with SeleniumGridConnector

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

the class TestSeleniumGridConnector method testIsGridActiveWithGridInError.

@Test(groups = { "ut" })
public void testIsGridActiveWithGridInError() throws ClientProtocolException, IOException, UnirestException {
    SeleniumGridConnector connector = new SeleniumGridConnector(SERVER_URL);
    createServerMock("GET", SeleniumGridConnector.CONSOLE_SERVLET, 500, "some text");
    Assert.assertFalse(connector.isGridActive());
}
Also used : SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with SeleniumGridConnector

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

the class TestSeleniumGridConnector method testGetSessionInformationFromGridWithSecondDriver.

/**
 * @throws UnsupportedOperationException
 * @throws IOException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testGetSessionInformationFromGridWithSecondDriver() throws UnsupportedOperationException, IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, UnirestException {
    createServerMock("GET", "/grid/api/testsession/", 200, "{'proxyId': 'http://localhost:43210'}");
    // prepare app file
    ((DesiredCapabilities) capabilities).setCapability(CapabilityType.BROWSER_NAME, "firefox");
    ((DesiredCapabilities) capabilities).setCapability(CapabilityType.BROWSER_VERSION, "50.0");
    // prepare response
    InputStream is = new StringInputStream("{'proxyId':'proxy//node:0'}");
    when(entity.getContent()).thenReturn(is);
    SeleniumGridConnector connector = spy(new SeleniumGridConnector(SERVER_URL));
    // 2 drivers created inside the same test
    connector.getSessionInformationFromGrid(driver);
    connector.getSessionInformationFromGrid(driver2);
    // issue #242: check sessionId is set only once when first driver is created
    verify(connector).setSessionId(any(SessionId.class));
    Assert.assertEquals(connector.getNodeUrl(), "http://localhost:43210");
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) InputStream(java.io.InputStream) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) SessionId(org.openqa.selenium.remote.SessionId) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with SeleniumGridConnector

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

the class TestSeleniumGridConnector method testIsGridActiveWithGridNotPresent.

@Test(groups = { "ut" })
public void testIsGridActiveWithGridNotPresent() throws ClientProtocolException, IOException, UnirestException {
    SeleniumGridConnector connector = new SeleniumGridConnector(SERVER_URL);
    when(Unirest.get(SERVER_URL + SeleniumGridConnector.CONSOLE_SERVLET)).thenReturn(getRequest);
    when(getRequest.asString()).thenThrow(UnirestException.class);
    Assert.assertFalse(connector.isGridActive());
}
Also used : SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with SeleniumGridConnector

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

the class TestSeleniumRobotGridConnector method testIsGridActiveWithRobotGridActiveWithoutNodes.

/**
 * Check that we get false if the grid is ACTIVE and no node is present
 * @throws ClientProtocolException
 * @throws IOException
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testIsGridActiveWithRobotGridActiveWithoutNodes() throws ClientProtocolException, IOException {
    String hubStatus = "{" + "  \"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.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 25 with SeleniumGridConnector

use of com.seleniumtests.connectors.selenium.SeleniumGridConnector 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)

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