Search in sources :

Example 11 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestConfigReader method readConfigurationWithValueOverride.

@Test(groups = { "ut" })
public void readConfigurationWithValueOverride() {
    Map<String, TestVariable> config = new ConfigReader("DEV", null).readConfig(Thread.currentThread().getContextClassLoader().getResourceAsStream("tu/env.ini"));
    Assert.assertEquals(config.get("key1").getValue(), "value4", "Key override does not work");
}
Also used : ConfigReader(com.seleniumtests.core.config.ConfigReader) TestVariable(com.seleniumtests.core.TestVariable) XmlTest(org.testng.xml.XmlTest) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 12 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class BugTrackerReporter method generateReport.

@Override
protected void generateReport(Map<ITestContext, Set<ITestResult>> resultSet, String outdir, boolean optimizeReport, boolean finalGeneration) {
    for (Map.Entry<ITestContext, Set<ITestResult>> entry : resultSet.entrySet()) {
        ITestContext context = entry.getKey();
        for (ITestResult testResult : entry.getValue()) {
            // record only when all executions of a test method are done so that intermediate results (a failed test which has been retried) are not present in list
            if (!Boolean.TRUE.equals(TestNGResultUtils.getNoMoreRetry(testResult)) || TestNGResultUtils.isBugtrackerReportCreated(testResult)) {
                continue;
            }
            // done in case it was null (issue #81)
            SeleniumTestsContext testContext = SeleniumTestsContextManager.setThreadContextFromTestResult(context, testResult);
            BugTracker bugtrackerServer = testContext.getBugTrackerInstance();
            if (bugtrackerServer == null) {
                return;
            }
            // get all bugtracker options
            Map<String, String> issueOptions = new HashMap<>();
            for (TestVariable variable : testContext.getConfiguration().values()) {
                if (variable.getName().startsWith("bugtracker.")) {
                    issueOptions.put(variable.getName().replace("bugtracker.", ""), variable.getValue());
                }
            }
            // application data
            String application = testContext.getApplicationName();
            String environment = testContext.getTestEnv();
            String testNgName = testResult.getTestContext().getCurrentXmlTest().getName();
            String testName = TestNGResultUtils.getUniqueTestName(testResult);
            String description = String.format("Test '%s' failed\n", testName);
            if (testResult.getMethod().getDescription() != null && !testResult.getMethod().getDescription().trim().isEmpty()) {
                description += "Test goal: " + TestNGResultUtils.getTestDescription(testResult);
            }
            // search the last step to get screenshots and failure reason
            List<TestStep> testSteps = TestNGResultUtils.getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
            if (testSteps == null) {
                return;
            }
            // create issue only for failed tests and if it has not been created before
            if (testResult.getStatus() == ITestResult.FAILURE) {
                IssueBean issueBean = bugtrackerServer.createIssue(application, environment, testNgName, testName, description, testSteps, issueOptions);
                // log information on issue
                if (issueBean != null) {
                    if (issueBean.getId() != null && issueBean.getAccessUrl() != null) {
                        TestNGResultUtils.setTestInfo(testResult, "Issue", new HyperlinkInfo(issueBean.getId(), issueBean.getAccessUrl()));
                    } else if (issueBean.getId() != null) {
                        TestNGResultUtils.setTestInfo(testResult, "Issue", new StringInfo(issueBean.getId()));
                    }
                    TestNGResultUtils.setTestInfo(testResult, "Issue date", new StringInfo(issueBean.getCreationDate()));
                }
                TestNGResultUtils.setBugtrackerReportCreated(testResult, true);
            // close issue if test is now OK and a previous issue has been created
            } else if (testResult.getStatus() == ITestResult.SUCCESS) {
                bugtrackerServer.closeIssue(application, environment, testNgName, testName);
                TestNGResultUtils.setBugtrackerReportCreated(testResult, true);
            }
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Set(java.util.Set) SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) ITestResult(org.testng.ITestResult) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) HashMap(java.util.HashMap) TestVariable(com.seleniumtests.core.TestVariable) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) HyperlinkInfo(com.seleniumtests.reporter.info.HyperlinkInfo) ITestContext(org.testng.ITestContext) StringInfo(com.seleniumtests.reporter.info.StringInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestStringUtility method testInterpolateStringDoNotMaskPassword1.

@Test(groups = { "ut" })
public void testInterpolateStringDoNotMaskPassword1() {
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("password", new TestVariable("password", "abc"));
    Assert.assertEquals(StringUtility.interpolateString("connect with ${password}", SeleniumTestsContextManager.getThreadContext(), false), "connect with abc");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 14 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestStringUtility method testInterpolateStringDoNotMaskPassword.

@Test(groups = { "ut" })
public void testInterpolateStringDoNotMaskPassword() {
    SeleniumTestsContextManager.getThreadContext().setMaskPassword(false);
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("pwd", new TestVariable("pwd", "abc"));
    Assert.assertEquals(StringUtility.interpolateString("connect with ${pwd}", SeleniumTestsContextManager.getThreadContext()), "connect with abc");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 15 with TestVariable

use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.

the class TestStringUtility method testInterpolateString.

@Test(groups = { "ut" })
public void testInterpolateString() {
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("url", new TestVariable("url", "http://mysite"));
    Assert.assertEquals(StringUtility.interpolateString("connect to ${url}", SeleniumTestsContextManager.getThreadContext()), "connect to http://mysite");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

TestVariable (com.seleniumtests.core.TestVariable)72 Test (org.testng.annotations.Test)66 GenericTest (com.seleniumtests.GenericTest)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 XmlTest (org.testng.xml.XmlTest)34 ConnectorsTest (com.seleniumtests.ConnectorsTest)19 MockitoTest (com.seleniumtests.MockitoTest)19 ITestResult (org.testng.ITestResult)14 HashMap (java.util.HashMap)13 SeleniumRobotVariableServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SeleniumTestsContext (com.seleniumtests.core.SeleniumTestsContext)7 File (java.io.File)3 ArrayList (java.util.ArrayList)3 JSONObject (kong.unirest.json.JSONObject)3 BrowserExtension (com.seleniumtests.browserfactory.BrowserExtension)2 ConfigReader (com.seleniumtests.core.config.ConfigReader)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 IOException (java.io.IOException)2 HttpRequest (kong.unirest.HttpRequest)2