Search in sources :

Example 6 with ConfigurationException

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

the class TestErrorCauseFinder method testCompareStepInErrorWithReferenceBadMatchErrorGettingReference2.

/**
 * Bad match: an exception occurs when getting reference snapshot
 * We should not fail
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testCompareStepInErrorWithReferenceBadMatchErrorGettingReference2() 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);
    PowerMockito.whenNew(StepReferenceComparator.class).withArguments(new File(stepFailed.getSnapshots().get(0).getScreenshot().getFullImagePath()), referenceImgStep1).thenReturn(stepReferenceComparatorStep1);
    // bad comparison with step2 reference
    when(stepReferenceComparatorStep2.compare()).thenReturn(49);
    // exception occurs when getting reference on step 1
    when(serverConnector.getReferenceSnapshot(0)).thenThrow(new ConfigurationException(""));
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).compareStepInErrorWithReference();
    Assert.assertEquals(causes.size(), 1);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.UNKNOWN_PAGE);
    Assert.assertNull(causes.get(0).getDescription());
    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)

Example 7 with ConfigurationException

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

the class Element method createTouchAction.

/**
 * Creates a TouchAction depending on mobile platform. Due to appium 6.0.0 changes
 * @return
 */
protected TouchAction<?> createTouchAction() {
    String platform = SeleniumTestsContextManager.getThreadContext().getPlatform();
    PerformsTouchActions performTouchActions = checkForMobile();
    if (platform.toLowerCase().startsWith("android")) {
        return new TouchAction<>(performTouchActions);
    } else if (platform.toLowerCase().startsWith("ios")) {
        return new TouchAction<>(performTouchActions);
    } else {
        throw new ConfigurationException(String.format("%s platform is not supported", platform));
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) PerformsTouchActions(io.appium.java_client.PerformsTouchActions) TouchAction(io.appium.java_client.TouchAction)

Example 8 with ConfigurationException

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

the class GenericPictureElement method createFileFromResource.

protected static File createFileFromResource(String resource) {
    try {
        File tempFile = File.createTempFile("img", null);
        tempFile.deleteOnExit();
        FileUtils.copyInputStreamToFile(Thread.currentThread().getContextClassLoader().getResourceAsStream(resource), tempFile);
        return tempFile;
    } catch (IOException | NullPointerException e) {
        throw new ConfigurationException(String.format("Resource '%s' cannot be found", resource), e);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 9 with ConfigurationException

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

the class JiraConnector method closeIssue.

/**
 * Close issue, applying all necessary transitions
 * @param issueId           ID of the issue
 * @param closingMessage    Message of closing
 */
public void closeIssue(String issueId, String closingMessage) {
    logger.info(String.format("closing issue %s", issueId));
    IssueRestClient issueClient = restClient.getIssueClient();
    Issue issue;
    try {
        issue = issueClient.getIssue(issueId).claim();
    } catch (RestClientException e) {
        throw new ScenarioException(String.format("Jira issue %s does not exist, cannot close it", issueId));
    }
    Map<String, Transition> transitions = new HashMap<>();
    issueClient.getTransitions(issue).claim().forEach(transition -> transitions.put(transition.getName(), transition));
    List<String> closeWorkflow = Arrays.asList(closeTransition.split("/"));
    int workflowPosition = -1;
    for (String transitionName : transitions.keySet()) {
        workflowPosition = closeWorkflow.indexOf(transitionName);
        if (workflowPosition != -1) {
            break;
        }
    }
    if (workflowPosition == -1) {
        throw new ConfigurationException(String.format("'bugtracker.jira.closeTransition' values [%s] are unknown for this issue, allowed transitions are %s", closeTransition, transitions.keySet()));
    } else {
        for (String transitionName : closeWorkflow.subList(workflowPosition, closeWorkflow.size())) {
            transitionIssue(issueClient, issue, transitions, transitionName);
        }
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) HashMap(java.util.HashMap) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 10 with ConfigurationException

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

the class JiraConnector method createIssue.

/**
 * Create issue
 */
public void createIssue(IssueBean issueBean) {
    if (!(issueBean instanceof JiraBean)) {
        throw new ClassCastException("JiraConnector needs JiraBean instances");
    }
    JiraBean jiraBean = (JiraBean) issueBean;
    IssueType issueType = issueTypes.get(jiraBean.getIssueType());
    if (issueType == null) {
        throw new ConfigurationException(String.format("Issue type %s cannot be found among valid issue types %s", jiraBean.getIssueType(), issueTypes.keySet()));
    }
    Map<String, CimFieldInfo> fieldInfos = getCustomFieldInfos(project, issueType);
    IssueRestClient issueClient = restClient.getIssueClient();
    IssueInputBuilder issueBuilder = new IssueInputBuilder(project, issueType, jiraBean.getSummary()).setDescription(jiraBean.getDescription());
    if (isDueDateRequired(fieldInfos)) {
        issueBuilder.setDueDate(jiraBean.getJodaDateTime());
    }
    if (jiraBean.getAssignee() != null && !jiraBean.getAssignee().isEmpty()) {
        User user = getUser(jiraBean.getAssignee());
        if (user == null) {
            throw new ConfigurationException(String.format("Assignee %s cannot be found among jira users", jiraBean.getAssignee()));
        }
        issueBuilder.setAssignee(user);
    }
    if (jiraBean.getPriority() != null && !jiraBean.getPriority().isEmpty()) {
        Priority priority = priorities.get(jiraBean.getPriority());
        if (priority == null) {
            throw new ConfigurationException(String.format("Priority %s cannot be found on this jira project, valid priorities are %s", jiraBean.getPriority(), priorities.keySet()));
        }
        issueBuilder.setPriority(priority);
    }
    if (jiraBean.getReporter() != null && !jiraBean.getReporter().isEmpty()) {
        issueBuilder.setReporterName(jiraBean.getReporter());
    }
    // set fields
    setCustomFields(jiraBean, fieldInfos, issueBuilder);
    // set components
    issueBuilder.setComponents(jiraBean.getComponents().stream().filter(component -> components.get(component) != null).map(component -> components.get(component)).collect(Collectors.toList()).toArray(new BasicComponent[] {}));
    // add issue
    IssueInput newIssue = issueBuilder.build();
    BasicIssue basicIssue = issueClient.createIssue(newIssue).claim();
    Issue issue = issueClient.getIssue(basicIssue.getKey()).claim();
    addAttachments(jiraBean, issueClient, issue);
    jiraBean.setId(issue.getKey());
    jiraBean.setAccessUrl(browseUrl + issue.getKey());
}
Also used : Arrays(java.util.Arrays) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URISyntaxException(java.net.URISyntaxException) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) HashMap(java.util.HashMap) Snapshot(com.seleniumtests.reporter.logger.Snapshot) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Logger(org.apache.log4j.Logger) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) WaitHelper(com.seleniumtests.util.helper.WaitHelper) ImmutableList(com.google.common.collect.ImmutableList) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Project(com.atlassian.jira.rest.client.api.domain.Project) URI(java.net.URI) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) CustomFieldOption(com.atlassian.jira.rest.client.api.domain.CustomFieldOption) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Field(com.atlassian.jira.rest.client.api.domain.Field) Collectors(java.util.stream.Collectors) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) List(java.util.List) User(com.atlassian.jira.rest.client.api.domain.User) Version(com.atlassian.jira.rest.client.api.domain.Version) BasicProject(com.atlassian.jira.rest.client.api.domain.BasicProject) TestStep(com.seleniumtests.reporter.logger.TestStep) Entry(java.util.Map.Entry) Comment(com.atlassian.jira.rest.client.api.domain.Comment) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) User(com.atlassian.jira.rest.client.api.domain.User) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)

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