Search in sources :

Example 36 with ScenarioException

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()));
    }
}
Also used : IOException(java.io.IOException) Sheet(org.apache.poi.ss.usermodel.Sheet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Workbook(org.apache.poi.ss.usermodel.Workbook) ScenarioException(com.seleniumtests.customexception.ScenarioException) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator) DataFormatter(org.apache.poi.ss.usermodel.DataFormatter)

Example 37 with ScenarioException

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;
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 38 with ScenarioException

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;
}
Also used : WebUIDriver(com.seleniumtests.driver.WebUIDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 39 with ScenarioException

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;
    }
}
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) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) File(java.io.File) ScenarioException(com.seleniumtests.customexception.ScenarioException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException)

Example 40 with ScenarioException

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);
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) HashMap(java.util.HashMap) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Aggregations

ScenarioException (com.seleniumtests.customexception.ScenarioException)68 ArrayList (java.util.ArrayList)17 WebElement (org.openqa.selenium.WebElement)14 UnirestException (kong.unirest.UnirestException)13 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)12 IOException (java.io.IOException)12 JSONObject (kong.unirest.json.JSONObject)12 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)11 Element (com.seleniumtests.uipage.htmlelements.Element)11 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)11 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)11 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)11 File (java.io.File)10 List (java.util.List)9 HashMap (java.util.HashMap)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 AWTException (java.awt.AWTException)7 Robot (java.awt.Robot)6 Map (java.util.Map)5 TestStep (com.seleniumtests.reporter.logger.TestStep)4