Search in sources :

Example 31 with ScenarioException

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

the class CampaignFolder method create.

public static CampaignFolder create(Project project, CampaignFolder parent, String campaignFolderName) {
    try {
        JSONObject body = new JSONObject();
        body.put(FIELD_TYPE, TYPE_CAMPAIGN_FOLDER);
        body.put(FIELD_NAME, campaignFolderName);
        if (parent != null) {
            body.put(FIELD_PARENT, parent.asJson());
        } else {
            body.put(FIELD_PARENT, project.asJson());
        }
        JSONObject json = getJSonResponse(buildPostRequest(apiRootUrl + CAMPAIGN_FOLDER_URL).body(body));
        return CampaignFolder.fromJson(json);
    } catch (UnirestException e) {
        throw new ScenarioException(String.format("Cannot create campaign %s", campaignFolderName), e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) UnirestException(kong.unirest.UnirestException) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 32 with ScenarioException

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

the class Iteration method create.

public static Iteration create(Campaign campaign, String iterationName) {
    try {
        JSONObject body = new JSONObject();
        body.put(FIELD_TYPE, TYPE_ITERATION);
        body.put(FIELD_NAME, iterationName);
        JSONObject parent = new JSONObject();
        parent.put(FIELD_ID, campaign.id);
        parent.put(FIELD_TYPE, TYPE_CAMPAIGN);
        body.put(FIELD_PARENT, parent);
        JSONObject json = getJSonResponse(buildPostRequest(String.format(apiRootUrl + ITERATIONS_URL, campaign.id)).body(body));
        return fromJson(json);
    } catch (UnirestException e) {
        throw new ScenarioException(String.format("Cannot create campaign %s", iterationName), e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) UnirestException(kong.unirest.UnirestException) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 33 with ScenarioException

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

the class Iteration method getAllTestCases.

public List<IterationTestPlanItem> getAllTestCases() {
    try {
        JSONObject json = getPagedJSonResponse(buildGetRequest(apiRootUrl + String.format(IterationTestPlanItem.TEST_PLAN_ITEM_URL, id)));
        List<IterationTestPlanItem> testPlanItems = new ArrayList<>();
        if (json.has(FIELD_EMBEDDED)) {
            for (JSONObject tpiJson : (List<JSONObject>) json.getJSONObject(FIELD_EMBEDDED).getJSONArray("test-plan").toList()) {
                testPlanItems.add(IterationTestPlanItem.fromJson(tpiJson));
            }
        }
        return testPlanItems;
    } catch (UnirestException e) {
        throw new ScenarioException("Cannot get all test cases", e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) ArrayList(java.util.ArrayList) UnirestException(kong.unirest.UnirestException) List(java.util.List) ArrayList(java.util.ArrayList) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 34 with ScenarioException

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

the class Project method getCampaigns.

public List<Campaign> getCampaigns() {
    try {
        JSONObject json = getPagedJSonResponse(buildGetRequest(url + CAMPAIGNS_URL));
        List<Campaign> campaigns = new ArrayList<>();
        if (json.has(FIELD_EMBEDDED)) {
            for (JSONObject folderJson : (List<JSONObject>) json.getJSONObject(FIELD_EMBEDDED).getJSONArray(FIELD_CAMPAIGNS).toList()) {
                campaigns.add(Campaign.fromJson(folderJson));
            }
        }
        return campaigns;
    } catch (UnirestException e) {
        throw new ScenarioException(String.format("Cannot get list of campaigns for project %s", name));
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) ArrayList(java.util.ArrayList) UnirestException(kong.unirest.UnirestException) List(java.util.List) ArrayList(java.util.ArrayList) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 35 with ScenarioException

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

the class ExcelHelper method readSheet.

public List<Map<String, String>> readSheet(Sheet sheet, boolean headerPresent, FormulaEvaluator formulaEvaluator, DataFormatter dataFormatter) {
    List<Map<String, String>> content = new ArrayList<>();
    int firstRow = sheet.getFirstRowNum();
    int lastRow = sheet.getLastRowNum();
    int firstColumn = 100000;
    int lastColumn = 0;
    Row headerRow = sheet.getRow(firstRow);
    List<String> headers = new ArrayList<>();
    // sheet is empty
    if (headerRow == null) {
        return null;
    }
    for (Cell cell : headerRow) {
        firstColumn = Math.min(cell.getColumnIndex(), firstColumn);
        lastColumn = Math.max(cell.getColumnIndex(), lastColumn);
        if (headerPresent) {
            headers.add(readCell(formulaEvaluator, dataFormatter, cell));
        } else {
            headers.add(Integer.toString(cell.getColumnIndex()));
        }
    }
    firstRow = headerPresent ? firstRow + 1 : firstRow;
    int colIdx = 0;
    for (int rowIdx = firstRow; rowIdx <= lastRow; rowIdx++) {
        try {
            Row row = sheet.getRow(rowIdx);
            if (row == null) {
                // nothing has been written in cell, it's null
                continue;
            }
            int empytCells = 0;
            Map<String, String> rowContent = new HashMap<>();
            for (colIdx = firstColumn; colIdx <= lastColumn; colIdx++) {
                Cell cell = row.getCell(colIdx);
                if (cell == null) {
                    // cell is empty, it's never been used
                    rowContent.put(headers.get(colIdx), "");
                    empytCells++;
                } else {
                    String cellContent = readCell(formulaEvaluator, dataFormatter, cell);
                    if (cellContent != null && cellContent.isEmpty()) {
                        empytCells++;
                    }
                    rowContent.put(headers.get(colIdx), cellContent);
                }
            }
            if (empytCells < rowContent.size()) {
                content.add(rowContent);
            }
        } catch (Exception e) {
            throw new ScenarioException(String.format("problem reading Excel sheet %s, line %d, column %d", sheet.getSheetName(), rowIdx + 1, colIdx + 1), e);
        }
    }
    return content;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Row(org.apache.poi.ss.usermodel.Row) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Cell(org.apache.poi.ss.usermodel.Cell) IOException(java.io.IOException) ScenarioException(com.seleniumtests.customexception.ScenarioException) 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