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));
}
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));
}
}
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);
}
}
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);
}
}
}
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());
}
Aggregations