use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.
the class TestTasks method createOrUpdateParam.
/**
* Method for creating or updating a variable. If variables are get from seleniumRobot server, this method will update the value on the server
* Moreover, created custom variable is specific to tuple (application, version, test environment)
* @param key name of the param
* @param newValue value of the parameter (or new value if we update it)
* @param specificToVersion if true, this param will be stored on server with a reference to the application version. This will have no effect if changing a
* current variable.
* @param timeToLive if > 0, this variable will be destroyed after some days (defined by variable). A positive value is mandatory if reservable is set to true
* because multiple variable can be created
* @param reservable if true, this variable will be set as reservable in variable server. This means it can be used by only one test at the same time
* True value also means that multiple variables of the same name can be created and a timeToLive > 0 MUST be provided so that server database is regularly purged
* @param localUpdateOnly it true, value won't be set on remote server
*/
public static void createOrUpdateParam(String key, String newValue, boolean specificToVersion, int timeToLive, boolean reservable, boolean localUpdateOnly) {
SeleniumRobotVariableServerConnector variableServer = SeleniumTestsContextManager.getThreadContext().getVariableServer();
if (reservable && timeToLive <= 0) {
throw new ScenarioException("When creating a variable as reservable, a positive timeToLive value MUST be provided");
}
// check if we update an existing variable
TestVariable variable = SeleniumTestsContextManager.getThreadContext().getConfiguration().get(key);
if (variable == null || reservable) {
variable = new TestVariable(key, newValue);
} else {
variable.setValue(newValue);
}
variable.setReservable(reservable);
variable.setTimeToLive(timeToLive);
if (variableServer != null && !localUpdateOnly) {
variable = variableServer.upsertVariable(variable, specificToVersion);
}
SeleniumTestsContextManager.getThreadContext().getConfiguration().put(variable.getName(), variable);
}
use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.
the class TestSeleniumRobotVariableServerConnector method testCreateVersionWithoutToken.
/**
* Check tokens are not added to request when not provided
* @throws UnirestException
*/
@Test(groups = { "ut" })
public void testCreateVersionWithoutToken() throws UnirestException {
configureMockedVariableServerConnection();
SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
connector.createVersion();
verify(createVersionRequest, never()).header(eq("Authorization"), anyString());
}
use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.
the class TestSeleniumRobotVariableServerConnector method testGetApplicationIdWithToken.
/**
* Check tokens are not added to request when not provided
* @throws UnirestException
*/
@Test(groups = { "ut" })
public void testGetApplicationIdWithToken() throws UnirestException {
configureMockedVariableServerConnection();
SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", "123");
Assert.assertEquals(connector.getApplicationId(), 1);
verify(namedApplicationRequest, times(1)).header("Authorization", "Token 123");
}
use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.
the class TestSeleniumRobotVariableServerConnector method testCreateVersionWithToken.
/**
* Check tokens are not added to request when not provided
* @throws UnirestException
*/
@Test(groups = { "ut" })
public void testCreateVersionWithToken() throws UnirestException {
configureMockedVariableServerConnection();
SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", "123");
connector.createVersion();
verify(createVersionRequest, times(2)).header("Authorization", "Token 123");
}
use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.
the class TestSeleniumRobotVariableServerConnector method testFetchVariableFailed.
/**
* get variables failes with error on server side
* @throws UnirestException
*/
@Test(groups = { "ut" }, expectedExceptions = SeleniumRobotServerException.class)
public void testFetchVariableFailed() throws UnirestException {
configureMockedVariableServerConnection();
createServerMock(SERVER_URL, "GET", SeleniumRobotVariableServerConnector.VARIABLE_API_URL, 404, "{}");
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");
}
Aggregations