Search in sources :

Example 6 with SeleniumRobotVariableServerConnector

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

the class TestSeleniumRobotVariableServerConnector method testServerWithRedirect308.

/**
 * Issue #356: check we change URL if redirect 308 is encountered
 */
@Test(groups = { "ut" })
public void testServerWithRedirect308() {
    // connection for HTTP
    configureMockedVariableServerConnection();
    // connection for HTTPS
    configureMockedVariableServerConnection("https://localhost:2345");
    HttpResponse<String> response = mock(HttpResponse.class);
    when(response.getBody()).thenReturn("Moved Permanently");
    when(response.getHeaders()).thenReturn(headers);
    when(response.getStatus()).thenReturn(308);
    when(responseHttps.getBody()).thenReturn("OK");
    when(responseHttps.getStatus()).thenReturn(200);
    when(headers.getFirst("Location")).thenReturn("https://localhost:2345");
    when(getAliveRequest.asString()).thenReturn(response);
    when(getAliveRequestHttps.asString()).thenReturn(responseHttps);
    when(unirestInstance.get(SERVER_URL + "/variable/api/")).thenReturn(getAliveRequest);
    when(Unirest.get("https://localhost:2345/variable/api/")).thenReturn(getAliveRequestHttps);
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
    Assert.assertEquals(connector.getUrl(), "https://localhost:2345");
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with SeleniumRobotVariableServerConnector

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

the class TestSeleniumRobotVariableServerConnector method testVariableRecreateExistingVariable.

/**
 * Variable is re-created when user has changed the value of a non-custom variable
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testVariableRecreateExistingVariable() throws UnirestException {
    configureMockedVariableServerConnection();
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
    TestVariable existingVariable = new TestVariable(12, "key", "value", false, "key");
    TestVariable variable = connector.upsertVariable(existingVariable, true);
    PowerMockito.verifyStatic(Unirest.class);
    Unirest.post(ArgumentMatchers.contains(SeleniumRobotVariableServerConnector.VARIABLE_API_URL));
    Assert.assertEquals(variable.getValue(), "value");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with SeleniumRobotVariableServerConnector

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

the class TestSeleniumRobotVariableServerConnector method testFetchVariableWithNetworkError.

@Test(groups = { "ut" }, expectedExceptions = SeleniumRobotServerException.class)
public void testFetchVariableWithNetworkError() throws UnirestException {
    configureMockedVariableServerConnection();
    HttpRequest<HttpRequest> req = createServerMock(SERVER_URL, "GET", SeleniumRobotVariableServerConnector.VARIABLE_API_URL, 200, "{}");
    when(req.asString()).thenThrow(UnirestException.class);
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
    Map<String, TestVariable> variables = connector.getVariables();
    Assert.assertEquals(variables.get("key1").getValue(), "value1");
    Assert.assertEquals(variables.get("key2").getValue(), "value2");
}
Also used : HttpRequest(kong.unirest.HttpRequest) TestVariable(com.seleniumtests.core.TestVariable) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with SeleniumRobotVariableServerConnector

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

the class TestSeleniumRobotVariableServerConnector method testVariableUpdateExistingVariableWithServerError.

@Test(groups = { "ut" }, expectedExceptions = SeleniumRobotServerException.class)
public void testVariableUpdateExistingVariableWithServerError() throws UnirestException {
    configureMockedVariableServerConnection();
    createServerMock(SERVER_URL, "PATCH", String.format(SeleniumRobotVariableServerConnector.EXISTING_VARIABLE_API_URL, 12), 500, "{}");
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
    TestVariable existingVariable = new TestVariable(12, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
    connector.upsertVariable(existingVariable, true);
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with SeleniumRobotVariableServerConnector

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

the class TestSeleniumRobotVariableServerConnector method testServerNotActive.

@Test(groups = { "ut" })
public void testServerNotActive() {
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(false, SERVER_URL, "Test1", null);
    Assert.assertFalse(connector.getActive());
}
Also used : SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SeleniumRobotVariableServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector)36 ConnectorsTest (com.seleniumtests.ConnectorsTest)34 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)34 Test (org.testng.annotations.Test)34 TestVariable (com.seleniumtests.core.TestVariable)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 HttpRequest (kong.unirest.HttpRequest)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 ArrayList (java.util.ArrayList)1 SkipException (org.testng.SkipException)1 BeforeMethod (org.testng.annotations.BeforeMethod)1