Search in sources :

Example 16 with AutomationException

use of exceptions.AutomationException in project cvs-auto-svc by dvsa.

the class WebDriverBrowsertack method checkAtfEmailDetails.

public static void checkAtfEmailDetails(WebDriver driver, String testStationName, String testStationPNumber, String testerName, String startDate, String startTime) {
    FluentWait wait = new FluentWait<>(driver).withTimeout(Duration.ofSeconds(10)).pollingEvery(Duration.ofMillis(250)).ignoring(NoSuchElementException.class);
    System.out.println("Checking the email title details are correct");
    wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[role='main']>div:nth-of-type(1)")), ExpectedConditions.presenceOfElementLocated(By.cssSelector("div[role='main']>div:nth-of-type(1)"))));
    String actualString = driver.findElement(By.cssSelector("div[role='main']>div:nth-of-type(1)")).getText();
    String expectedString = "DVSA Commercial Vehicle Service – Site Activity Report: " + testStationPNumber + " – " + testerName + " – " + startDate;
    try {
        assertEquals(expectedString, actualString);
    } catch (AssertionError e) {
        throw new AutomationException("Expected string " + expectedString + " is not identical to actual string " + actualString);
    }
    System.out.println("Checking the details in the email are correct");
    wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("div[class^='rps']>div>table:nth-of-type(4)>tbody>tr:nth-of-type(2)>td:nth-of-type(2)>p:first-of-type"), 0));
    String actualString1 = driver.findElement(By.cssSelector("div[class^='rps']>div>table:nth-of-type(4)>tbody>tr:nth-of-type(2)>td:nth-of-type(2)>p:first-of-type")).getText();
    String expectedString1 = "Please find below the report for the activities conducted on " + startDate + " by " + testerName + ".";
    try {
        assertTrue(actualString1.contains(expectedString1));
    } catch (AssertionError e) {
        throw new AutomationException("Actual string '" + actualString1 + "' does not contain expected string '" + expectedString1 + "'");
    }
    wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[class^='rps']>div>table:nth-of-type(4)>tbody>tr:nth-of-type(2)>td:nth-of-type(2)>p:nth-of-type(3)")), ExpectedConditions.presenceOfElementLocated(By.cssSelector("div[class^='rps']>div>table:nth-of-type(4)>tbody>tr:nth-of-type(2)>td:nth-of-type(2)>p:nth-of-type(3)"))));
    String siteVisitDetailsText = driver.findElement(By.cssSelector("div[class^='rps']>div>table:nth-of-type(4)>tbody>tr:nth-of-type(2)>td:nth-of-type(2)>p:nth-of-type(3)")).getText();
    String expectedString2 = "Site: " + testStationName + " – " + testStationPNumber;
    String expectedString3 = "Assessor: " + testerName;
    String expectedString4 = "Date: " + startDate;
    String expectedString5 = "Start Time: " + startTime;
    try {
        assertTrue(siteVisitDetailsText.contains(expectedString2));
    } catch (AssertionError e) {
        throw new AutomationException("Actual string '" + siteVisitDetailsText + "' does not contain expected string '" + expectedString2 + "'");
    }
    try {
        assertTrue(siteVisitDetailsText.contains(expectedString3));
    } catch (AssertionError e) {
        throw new AutomationException("Actual string '" + siteVisitDetailsText + "' does not contain expected string '" + expectedString3 + "'");
    }
    try {
        assertTrue(siteVisitDetailsText.contains(expectedString4));
    } catch (AssertionError e) {
        throw new AutomationException("Actual string '" + siteVisitDetailsText + "' does not contain expected string '" + expectedString4 + "'");
    }
    try {
        assertTrue(siteVisitDetailsText.contains(expectedString5));
    } catch (AssertionError e) {
        throw new AutomationException("Actual string '" + siteVisitDetailsText + "' does not contain expected string '" + expectedString5 + "'");
    }
    driver.close();
    driver.quit();
}
Also used : FluentWait(org.openqa.selenium.support.ui.FluentWait) AutomationException(exceptions.AutomationException)

Example 17 with AutomationException

use of exceptions.AutomationException in project cvs-auto-svc by dvsa.

the class DataMapper method getTestTypeById.

public static TestTypeById getTestTypeById(String testTypeClassification, String forVehicleType, String forVehicleSize, String forVehicleConfiguration, String forVehicleAxles) {
    TestTypeById testTypeByIdReturned = null;
    ClassLoader classLoader = new DataMapper().getClass().getClassLoader();
    try {
        ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        TestTypeById[] node = objectMapper.readValue(readFromInputStream(classLoader.getResourceAsStream("loader/" + BaseData.getDataLocation() + "/test-type-by-id.json")), TestTypeById[].class);
        List<TestTypeById> list = Arrays.asList(node);
        testTypeByIdReturned = findTestType(list, testTypeClassification, forVehicleType, forVehicleSize, forVehicleConfiguration, forVehicleAxles);
    } catch (IOException e) {
        throw new AutomationException("Error: " + e.getMessage());
    }
    if (testTypeByIdReturned == null) {
        throw new AutomationException("Error finding test type by id. Check file contents: test-type-by-id.json");
    }
    return testTypeByIdReturned;
}
Also used : TestTypeById(model.testtypeid.TestTypeById) AutomationException(exceptions.AutomationException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

AutomationException (exceptions.AutomationException)17 Response (io.restassured.response.Response)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JSONObject (org.json.JSONObject)4 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 FluentWait (org.openqa.selenium.support.ui.FluentWait)3 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)2 Regions (com.amazonaws.regions.Regions)2 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)2 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)2 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)2 AssumeRoleResult (com.amazonaws.services.securitytoken.model.AssumeRoleResult)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 TestTypeById (model.testtypeid.TestTypeById)2 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)2 TestTypeField (clients.model.TestTypeField)1 TestTypes (clients.model.TestTypes)1