use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class ExcelHelper method readSheet.
/**
* Read a sheet by index in the excel file
* @param fis
* @param sheetName
* @return
* @throws IOException
*/
public List<Map<String, String>> readSheet(InputStream fis, int sheetIndex, boolean headerPresent) throws IOException {
try (Workbook workbook = WorkbookFactory.create(fis)) {
FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter dataFormatter = new DataFormatter();
Sheet sheet = workbook.getSheetAt(sheetIndex);
List<Map<String, String>> sheetContent = readSheet(sheet, headerPresent, formulaEvaluator, dataFormatter);
if (sheetContent == null) {
throw new ScenarioException(String.format("No data in sheet %d", sheetIndex));
}
return sheetContent;
} catch (IOException e) {
throw new ScenarioException(e.getMessage());
} catch (IllegalArgumentException e) {
throw new ScenarioException(String.format("Sheet numbered %d does not exist: %s", sheetIndex, e.getMessage()));
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class VideoRecorder method stop.
public File stop() throws IOException {
if (screenRecorder == null) {
throw new ScenarioException("recorder is null!. do not use the default constructor");
}
if (screenRecorder.getState() == State.RECORDING) {
window.dispose();
screenRecorder.stop();
List<File> createdFiles = screenRecorder.getCreatedMovieFiles();
if (!createdFiles.isEmpty()) {
File lastFile = createdFiles.get(createdFiles.size() - 1);
File videoFile = Paths.get(folderPath.getAbsolutePath(), fileName).toFile();
FileUtils.copyFile(lastFile, videoFile);
// remove temp files
for (File f : createdFiles) {
try {
Files.delete(Paths.get(f.getAbsolutePath()));
} catch (IOException e) {
logger.info("could not delete video temp file: " + e.getMessage());
}
}
return videoFile;
} else {
return null;
}
} else {
return null;
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class UiElement method getDriver.
public CustomEventFiringWebDriver getDriver() {
WebUIDriver uiDriver = WebUIDriver.getWebUIDriver(false);
if (uiDriver == null) {
throw new ScenarioException("Driver has not already been created");
}
CustomEventFiringWebDriver driver = (CustomEventFiringWebDriver) uiDriver.getDriver();
if (driver == null) {
throw new ScenarioException("Driver has not already been created");
}
return driver;
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class JiraConnector method updateIssue.
@Override
public void updateIssue(String issueId, String messageUpdate, List<ScreenShot> screenShots, TestStep lastFailedStep) {
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 update it", issueId));
}
try {
if (!screenShots.isEmpty()) {
issueClient.addAttachments(issue.getAttachmentsUri(), screenShots.stream().peek(s -> logger.info("file ->" + s.getFullImagePath())).map(s -> new File(s.getFullImagePath())).collect(Collectors.toList()).toArray(new File[] {}));
}
// add comment
issueClient.addComment(issue.getCommentsUri(), Comment.valueOf(formatUpdateDescription(messageUpdate, screenShots, lastFailedStep).toString()));
logger.info(String.format("Jira %s updated", issueId));
} catch (Exception e) {
logger.error(String.format("Jira %s not modified: %s", issueId, e.getMessage()));
throw e;
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class JiraConnector method main.
/**
* Method for getting required fields and allowed values for creating an issue on a project
*
* @param args
* server => url of jira server
* user => user to connect to jira
* password => password to connect to jira
* project => projectkey
* issueType => type of the issue that will be created
* issueKey (optional) => give the transitions for a specific issue
*/
public static void main(String[] args) {
if (args.length < 5) {
System.out.println("Usage: JiraConnector <server> <projectKey> <user> <password> <issueType>");
System.exit(1);
}
JiraConnector jiraConnector = new JiraConnector(args[0], args[1], args[2], args[3]);
IssueType issueType = jiraConnector.issueTypes.get(args[4]);
if (issueType == null) {
throw new ConfigurationException(String.format("Issue type %s cannot be found among valid issue types %s", args[4], jiraConnector.issueTypes.keySet()));
}
System.out.println("Proprities:");
for (String priority : jiraConnector.priorities.keySet()) {
System.out.println(String.format(ITEM, priority));
}
System.out.println("\nComponents:");
for (String component : jiraConnector.components.keySet()) {
System.out.println(String.format(ITEM, component));
}
System.out.println(String.format("\nListing required fields and allowed values (if any) for issue '%s'", args[4]));
Map<String, CimFieldInfo> fieldInfos = jiraConnector.getCustomFieldInfos(jiraConnector.project, issueType);
for (Entry<String, List<String>> entry : jiraConnector.getRequiredFieldsAndValues(fieldInfos).entrySet()) {
System.out.println(String.format("Field '%s':", entry.getKey()));
for (String value : entry.getValue()) {
System.out.println(String.format(ITEM, value));
}
}
if (args.length >= 6) {
IssueRestClient issueClient = jiraConnector.restClient.getIssueClient();
Issue issue;
try {
issue = issueClient.getIssue(args[5]).claim();
} catch (RestClientException e) {
throw new ScenarioException(String.format("Jira issue %s does not exist, cannot close it", args[5]));
}
Map<String, Transition> transitions = new HashMap<>();
issueClient.getTransitions(issue).claim().forEach(transition -> transitions.put(transition.getName(), transition));
System.out.println(transitions);
}
}
Aggregations