use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestSeleniumTestContext3 method testVariablesAreGetMultipleTimesWithContextCopy.
/**
* Check that when copying context, it's possible to allow it to retrieve
* variables from server
*
* @param testNGCtx
* @param xmlTest
* @throws Exception
*/
@Test(groups = { "ut" })
public void testVariablesAreGetMultipleTimesWithContextCopy(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
Map<String, TestVariable> variables = new HashMap<>();
variables.put("key", new TestVariable("key", "val1"));
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);
when(variableServer.getVariables(0)).thenReturn(variables);
ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
initThreadContext(testNGCtx, "myTest", testResult);
SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
// do a parameter retrieving for copied context. Context is copied with
// permitting calls to variable server
SeleniumTestsContext seleniumTestsCtx2 = new SeleniumTestsContext(seleniumTestsCtx);
seleniumTestsCtx2.configureContext(testResult);
// check that variables are kept even if variable server has not been re-called
Assert.assertEquals(seleniumTestsCtx2.getConfiguration().get("key").getValue(), "val1");
// 2 calls, one for each context because we allow variable retrieving when
// copying
verify(variableServer, times(2)).getVariables(0);
} finally {
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
}
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestSeleniumTestContext method testBugtrackerUrlFromVariable.
@Test(groups = "ut context")
public void testBugtrackerUrlFromVariable(final ITestContext testNGCtx, final XmlTest xmlTest) {
initThreadContext(testNGCtx);
SeleniumTestsContextManager.getThreadContext().getConfiguration().put("bugtrackerUrl", new TestVariable("bugtrackerUrl", "http://foo.bar2"));
Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getBugtrackerUrl(), "http://foo.bar2");
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestSeleniumTestContext method testAttributeFoundInVariableAndRequested.
@Test(groups = "ut context")
public void testAttributeFoundInVariableAndRequested(final ITestContext testNGCtx, final XmlTest xmlTest) {
initThreadContext(testNGCtx);
SeleniumTestsContextManager.getThreadContext().getConfiguration().put("foo2", new TestVariable("foo2", "bar2"));
SeleniumTestsContextManager.getThreadContext().setAttribute("foo", "bar");
Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getAttribute("foo2", true), "bar2");
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class ConfigReader method readConfig.
public Map<String, TestVariable> readConfig(InputStream iniFileStream, String environment) {
Map<String, TestVariable> testConfig = new HashMap<>();
try {
Ini ini = new Ini();
Config conf = ini.getConfig();
conf.setGlobalSection(true);
conf.setGlobalSectionName(GLOBAL_SECTION_NAME);
conf.setFileEncoding(StandardCharsets.UTF_8);
ini.setConfig(conf);
ini.load(iniFileStream);
Set<Entry<String, Section>> sections = ini.entrySet();
// first get global options
testConfig = getGlobalOptions(testConfig, sections);
// then overwrite global options with local ones
testConfig = getLocalOptions(testConfig, sections, environment);
return testConfig;
} catch (InvalidFileFormatException e) {
throw new ConfigurationException("Invalid ini/properties file: " + iniFileStream + ", check there is no BOM for encoding");
} catch (IOException e) {
throw new ConfigurationException(String.format("File does not exist %s: %s", iniFileStream, e.getMessage()));
}
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class ConfigReader method readConfig.
/**
* read configuration from default config file (env.ini or config.ini)
* read any other provided configuration files (through loadIni parameter)
* @return
*/
public Map<String, TestVariable> readConfig() {
Map<String, TestVariable> variables = new HashMap<>();
try (InputStream iniFileStream = FileUtils.openInputStream(getConfigFile())) {
variables.putAll(readConfig(iniFileStream, testEnv));
} catch (NullPointerException e) {
logger.warn("config file is null, check config path has been set using 'SeleniumTestsContextManager.generateApplicationPath()'");
return variables;
} catch (IOException e1) {
logger.warn("no valid config.ini file for this application");
return variables;
}
// read additional files
if (iniFiles != null) {
for (String fileName : iniFiles.split(",")) {
fileName = fileName.trim();
File currentConfFile = Paths.get(SeleniumTestsContextManager.getConfigPath(), fileName).toFile();
logger.info("reading file " + currentConfFile.getAbsolutePath());
try (InputStream iniFileStream = FileUtils.openInputStream(currentConfFile)) {
variables.putAll(readConfig(iniFileStream, testEnv));
} catch (IOException e) {
throw new ConfigurationException(String.format("File %s does not exist in data/<app>/config folder", fileName));
}
}
}
return variables;
}
Aggregations