use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestTasks method testUpdateExistingVariable.
/**
* Check that if variable exists but we request a reservable variable, it's recreated so that we can have multiple variables
* @param testNGCtx
* @param xmlTest
* @throws Exception
*/
@Test(groups = { "ut" })
public void testUpdateExistingVariable(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
try {
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
when(variableServer.isAlive()).thenReturn(true);
TestVariable varToReturn = new TestVariable(10, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
when(variableServer.upsertVariable(any(TestVariable.class), anyBoolean())).thenReturn(varToReturn);
SeleniumTestsContextManager.getThreadContext().getConfiguration().put("key", new TestVariable(10, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key", 2, null));
ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
initThreadContext(testNGCtx, "myTest", testResult);
TestTasks.createOrUpdateParam("key", "value", false, 3, true);
// check upsert has been called
verify(variableServer).upsertVariable(new TestVariable(null, "key", "value", true, "key", 3, null), false);
// check configuration is updated
Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getConfiguration().get("key"), varToReturn);
} finally {
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
}
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestTasks method testParamKeyPatternThreadContextNotInitialized.
/**
* Check we look at global context if thread context is not initialized
*/
@Test(groups = { "ut" })
public void testParamKeyPatternThreadContextNotInitialized() {
SeleniumTestsContextManager.setThreadContext(null);
SeleniumTestsContextManager.getGlobalContext().getConfiguration().put("foofoo", new TestVariable("foofoo", "bar2"));
Assert.assertEquals(TestTasks.param(Pattern.compile("ofo")), "bar2");
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestTasks method testUpdateNewVariableNotSpecificToVersion.
/**
* Check upsert of a new variable which will not be version specific
* Verify server is called and configuration is updated according to the new value
* @param testNGCtx
* @param xmlTest
* @throws Exception
*/
@Test(groups = { "ut" })
public void testUpdateNewVariableNotSpecificToVersion(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
try {
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
when(variableServer.isAlive()).thenReturn(true);
TestVariable varToReturn = new TestVariable(10, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
when(variableServer.upsertVariable(any(TestVariable.class), anyBoolean())).thenReturn(varToReturn);
ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
initThreadContext(testNGCtx, "myTest", testResult);
TestTasks.createOrUpdateParam("key", "value", false);
// check upsert has been called
verify(variableServer).upsertVariable(new TestVariable("key", "value"), false);
// check configuration is updated
Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getConfiguration().get("key"), varToReturn);
} finally {
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
}
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestTasks method testUpdateNewVariableLocally.
/**
* Check upsert of a new variable locally
* Verify server is not called and configuration is updated according to the new value
* @param testNGCtx
* @param xmlTest
* @throws Exception
*/
@Test(groups = { "ut" })
public void testUpdateNewVariableLocally(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
try {
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
when(variableServer.isAlive()).thenReturn(true);
ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
initThreadContext(testNGCtx, "myTest", testResult);
TestTasks.createOrUpdateLocalParam("key", "value");
// check upsert has been NOT called
verify(variableServer, never()).upsertVariable(new TestVariable("key", "value"), true);
// check configuration is updated
Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getConfiguration().get("key").getValue(), "value");
} finally {
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
}
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestTasks method testParamValuePatternDoesNotExist.
/**
* Check empty string is returned if parameter is not known
*/
@Test(groups = { "ut" })
public void testParamValuePatternDoesNotExist() {
SeleniumTestsContextManager.getThreadContext().getConfiguration().put("foofoo", new TestVariable("foofoo", "barbar"));
SeleniumTestsContextManager.getGlobalContext().getConfiguration().put("foobar", new TestVariable("foobar", "barbar2"));
Assert.assertEquals(TestTasks.param(null, Pattern.compile("rbba")), "");
}
Aggregations