use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.
the class TestSeleniumTestContext method testUserDefinedParamAddedToTestVariables.
/**
* Check that user defined arguments passed through command line (-DmyParam=myValue) is copied to testVariables and added to configuration
*/
@Test(groups = { "ut context" })
public void testUserDefinedParamAddedToTestVariables(final ITestContext testNGCtx) {
try {
System.setProperty("myUserDefinedKey", "myUserDefinedValue");
initThreadContext(testNGCtx);
SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("myUserDefinedKey").getValue(), "myUserDefinedValue");
} finally {
System.clearProperty("myUserDefinedKey");
}
}
use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.
the class TestSeleniumTestContext method testPlatformParsingForAndroid.
@Test(groups = { "ut context" })
public void testPlatformParsingForAndroid(final ITestContext testNGCtx, final XmlTest xmlTest) {
try {
System.setProperty("platform", "Android 5.0");
System.setProperty("deviceName", "");
initThreadContext(testNGCtx);
SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
Assert.assertEquals(seleniumTestsCtx.getPlatform(), "Android");
Assert.assertEquals(seleniumTestsCtx.getMobilePlatformVersion(), "5.0");
} finally {
System.clearProperty("platform");
System.clearProperty("deviceName");
}
}
use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.
the class TestSeleniumTestContext method testUserDefinedParamOverriesXMLUserDefined.
/**
* Check that when a user defined parameter is both defined in XML and on command line, the command line one has precedence
* @param testNGCtx
*/
@Test(groups = { "ut context" })
public void testUserDefinedParamOverriesXMLUserDefined(final ITestContext testNGCtx) {
try {
System.setProperty("variable1", "myUserDefinedValue");
initThreadContext(testNGCtx);
SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("variable1").getValue(), "myUserDefinedValue");
} finally {
System.clearProperty("variable1");
}
}
use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.
the class TestSeleniumTestContext method testUserDefinedParamOverridesEnvIni.
/**
* If parameter is defined in env.ini and as JVM parameter (user defined), the user defined parameter must be used
*/
@Test(groups = { "ut context" })
public void testUserDefinedParamOverridesEnvIni(final ITestContext testNGCtx, final XmlTest xmlTest) {
try {
System.setProperty("key1", "userValue");
initThreadContext(testNGCtx);
SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("key1").getValue(), "userValue");
} finally {
System.clearProperty("key1");
}
}
use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.
the class CustomReporter method generateTestReport.
/**
* Generates report for a single test
* @param testResult
*/
private void generateTestReport(ITestResult testResult, ReportInfo reportInfo) {
try {
VelocityEngine ve = createVelocityEngine();
Template t = ve.getTemplate(reportInfo.getTemplatePath());
VelocityContext context = new VelocityContext();
String reportFormat = reportInfo.getExtension().substring(1);
Long testDuration = 0L;
Integer errors = 0;
String failedStep = "";
List<TestStep> testSteps = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
List<TestStep> newTestSteps = new ArrayList<>();
if (testSteps != null) {
for (TestStep step : testSteps) {
testDuration += step.getDuration();
if (Boolean.TRUE.equals(step.getFailed()) && !step.isTestEndStep()) {
failedStep = step.getName();
errors++;
}
// encode each step
if ("xml".equalsIgnoreCase(reportFormat.toLowerCase()) || "json".equalsIgnoreCase(reportFormat.toLowerCase()) || "html".equalsIgnoreCase(reportFormat.toLowerCase()) || "csv".equalsIgnoreCase(reportFormat.toLowerCase())) {
newTestSteps.add(step.encode(reportFormat.toLowerCase()));
} else {
newTestSteps.add(step);
}
}
}
// issue #227: number of errors set to -1 to distinguish skipped tests
if (testResult.getStatus() == ITestResult.SKIP) {
errors = -1;
}
// because test result published by this report must conform to other results
if (testResult.getStatus() == ITestResult.SUCCESS) {
errors = 0;
}
List<String> stack = null;
if (testResult.getThrowable() != null) {
StringBuilder stackString = new StringBuilder();
ExceptionUtility.generateTheStackTrace(testResult.getThrowable(), testResult.getThrowable().getMessage(), stackString, reportFormat.toLowerCase());
stack = Arrays.asList(stackString.toString().split("\n"));
}
SeleniumTestsContext seleniumTestsContext = TestNGResultUtils.getSeleniumRobotTestContext(testResult);
// if adding some information, don't forget to add them to velocity model for integration tests
context.put("errors", 0);
context.put("newline", "\n");
context.put("failures", errors);
context.put("hostname", testResult.getHost() == null ? "" : testResult.getHost());
context.put("suiteName", TestNGResultUtils.getUniqueTestName(testResult));
context.put("className", testResult.getTestClass().getName());
context.put("tests", newTestSteps == null ? 0 : newTestSteps.size());
context.put("duration", testDuration / 1000.0);
context.put("time", testResult.getStartMillis());
context.put("startDate", new Date(testResult.getStartMillis()));
context.put("testSteps", newTestSteps);
context.put("retries", TestNGResultUtils.getRetry(testResult) == null ? 0 : TestNGResultUtils.getRetry(testResult));
context.put("browser", seleniumTestsContext.getBrowser());
context.put("mobileApp", StringUtility.encodeString(seleniumTestsContext.getApp(), reportFormat.toLowerCase()));
context.put("device", StringUtility.encodeString(seleniumTestsContext.getDeviceName() == null ? "" : seleniumTestsContext.getDeviceName(), reportFormat.toLowerCase()));
if (seleniumTestsContext.getTestType().isMobile()) {
context.put("platform", seleniumTestsContext.getPlatform() + " " + seleniumTestsContext.getMobilePlatformVersion());
} else {
context.put("platform", seleniumTestsContext.getPlatform());
}
context.put("version", SeleniumTestsContextManager.getApplicationVersion());
context.put("coreVersion", SeleniumTestsContextManager.getCoreVersion());
context.put("parameters", seleniumTestsContext.getContextDataMap());
context.put("stacktrace", stack);
context.put("failedStep", StringUtility.encodeString(failedStep, reportFormat.toLowerCase()));
String logs = SeleniumRobotLogger.getTestLogs().get(getTestName(testResult));
getTestLogs(context, reportFormat, logs);
context.put("testInfos", TestNGResultUtils.getTestInfoEncoded(testResult, reportFormat));
StringWriter writer = new StringWriter();
t.merge(context, writer);
String fileName = reportInfo.prefix + "-result" + reportInfo.extension;
generateReport(Paths.get(seleniumTestsContext.getOutputDirectory(), fileName).toFile(), writer.toString());
generatedFiles.add(fileName);
TestNGResultUtils.setCustomReportCreated(testResult, true);
} catch (Exception e) {
logger.error(String.format("Error generating test result %s: %s", TestNGResultUtils.getUniqueTestName(testResult), e.getMessage()));
}
}
Aggregations