Search in sources :

Example 61 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestBugTrackerReporter method testIssueNotRecordedMissingProject.

@Test(groups = { "it" })
public void testIssueNotRecordedMissingProject() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.BUGTRACKER_TYPE, "jira");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_URL, "http://localhost:1234");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_USER, "jira");
        System.setProperty(SeleniumTestsContext.BUGTRACKER_PASSWORD, "jira");
        PowerMockito.whenNew(JiraConnector.class).withAnyArguments().thenThrow(new ConfigurationException(""));
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForTestManager" }, ParallelMode.METHODS, new String[] { "testInError" });
        verify(jiraConnector, never()).createIssue(any(), any(), any(), any(), any(), any(), any());
    } finally {
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_TYPE);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_URL);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_USER);
        System.clearProperty(SeleniumTestsContext.BUGTRACKER_PASSWORD);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 62 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestTestManagerReporter method testResultIsNotRecordedServerUnavailable.

@Test(groups = { "it" })
public void testResultIsNotRecordedServerUnavailable() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.TMS_TYPE, "squash");
        System.setProperty(SeleniumTestsContext.TMS_URL, "http://localhost:1234");
        System.setProperty(SeleniumTestsContext.TMS_PROJECT, "Project");
        System.setProperty(SeleniumTestsContext.TMS_USER, "squash");
        System.setProperty(SeleniumTestsContext.TMS_PASSWORD, "squash");
        doThrow(new ConfigurationException("Cannot contact Squash TM server API")).when(squash).getApi();
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForTestManager" }, ParallelMode.METHODS, new String[] { "testAndSubActions" });
        // check no result has been recorded
        verify(api, never()).setExecutionResult(eq(iterationTestPlanItem), any());
    } finally {
        System.clearProperty(SeleniumTestsContext.TMS_TYPE);
        System.clearProperty(SeleniumTestsContext.TMS_PROJECT);
        System.clearProperty(SeleniumTestsContext.TMS_URL);
        System.clearProperty(SeleniumTestsContext.TMS_USER);
        System.clearProperty(SeleniumTestsContext.TMS_PASSWORD);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 63 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestOsUtility method testKillProcess.

@Test(groups = { "it" })
public void testKillProcess() {
    if (OSUtility.isWindows()) {
        OSCommand.executeCommand("calc");
        WaitHelper.waitForSeconds(2);
        ProcessInfo pi = osUtil.getRunningProcess("calc");
        if (pi == null) {
            // Windows 10
            pi = osUtil.getRunningProcess("calculator");
        }
        if (pi == null) {
            // Windows 10
            pi = osUtil.getRunningProcess("Calculator");
        }
        if (pi == null) {
            // Windows 2016
            pi = osUtil.getRunningProcess("win32calc");
        }
        if (pi == null) {
            throw new ConfigurationException("Cannot find process 'calc', 'win32calc' or 'calculator'");
        }
        osUtil.killProcess(pi.getPid(), true);
        Assert.assertNull(osUtil.getRunningProcess("calc"));
        Assert.assertNull(osUtil.getRunningProcess("calculator"));
        Assert.assertNull(osUtil.getRunningProcess("Calculator"));
        Assert.assertNull(osUtil.getRunningProcess("win32calc"));
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ProcessInfo(com.seleniumtests.util.osutility.ProcessInfo) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 64 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestSeleniumGridConnectorFactory method testWithError.

/**
 * If any error occurs when getting servlet, throw an error, grid cannot be contacted
 * Check also that we retry connection during N seconds (defined by retryTimeout)
 * @throws UnsupportedOperationException
 * @throws IOException
 * @throws UnirestException
 */
@Test(groups = { "ut" }, expectedExceptions = ConfigurationException.class)
public void testWithError() throws UnsupportedOperationException, IOException, UnirestException {
    when(Unirest.get(SERVER_URL + SeleniumGridConnector.CONSOLE_SERVLET)).thenReturn(gRequest);
    when(gRequest.asString()).thenThrow(UnirestException.class);
    LocalDateTime start = LocalDateTime.now();
    try {
        SeleniumGridConnectorFactory.setRetryTimeout(5);
        SeleniumGridConnectorFactory.getInstances(Arrays.asList(SERVER_URL + "/wd/hub"));
    } catch (ConfigurationException e) {
        // check connection duration
        Assert.assertTrue(LocalDateTime.now().minusSeconds(5).isAfter(start));
        throw e;
    } finally {
        SeleniumGridConnectorFactory.setRetryTimeout(SeleniumGridConnectorFactory.DEFAULT_RETRY_TIMEOUT);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 65 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceErrorInComparison.

/**
 * If any error occurs in comparison, continue
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceErrorInComparison() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, stepFailed, lastStep));
    // comparison successful
    PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep2).thenReturn(stepReferenceComparatorStep2);
    when(stepReferenceComparatorStep2.compare()).thenThrow(new ConfigurationException("error on init"));
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    Assert.assertEquals(causes.size(), 0);
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInReferencePicture(testResult));
}
Also used : ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

ConfigurationException (com.seleniumtests.customexception.ConfigurationException)66 ArrayList (java.util.ArrayList)19 File (java.io.File)18 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)13 Matcher (java.util.regex.Matcher)9 List (java.util.List)8 UnirestException (kong.unirest.UnirestException)8 GenericTest (com.seleniumtests.GenericTest)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ScenarioException (com.seleniumtests.customexception.ScenarioException)5 BrowserType (com.seleniumtests.driver.BrowserType)5 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 Collectors (java.util.stream.Collectors)5 Win32Exception (com.sun.jna.platform.win32.Win32Exception)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Files (java.nio.file.Files)4