use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class TestTypesClient method getRestrictions.
public JSONObject getRestrictions(String testCode) {
String testTypeProperties;
if (testCode.lastIndexOf("_") != -1) {
testTypeProperties = GenericData.readJsonValueFromFile("test-type.json", "$..[?(@.defaultTestCode == '" + testCode.split("_")[0] + "' && @.forVehicleType == '" + testCode.split("_")[1] + "')]");
} else {
if (testCode.contentEquals("lcp")) {
testTypeProperties = GenericData.readJsonValueFromFile("test-type.json", "$..[?(@.linkedTestCode == '" + testCode + "')]");
} else {
testTypeProperties = GenericData.readJsonValueFromFile("test-type.json", "$..[?(@.defaultTestCode == '" + testCode + "')]");
}
}
String restrictions = GenericData.getJsonObjectInPath(testTypeProperties, "$[0]");
JSONObject jsonObject;
try {
jsonObject = new JSONObject(restrictions);
} catch (JSONException err) {
throw new AutomationException("'" + restrictions + "' is not a valid JSON string");
}
Iterator keys = jsonObject.keys();
JSONObject actualRestrictions = new JSONObject();
while (keys.hasNext()) {
String key = keys.next().toString();
if (!(key.contentEquals("defaultTestCode")) && !(key.contentEquals("linkedTestCode"))) {
try {
if (!jsonObject.get(key).toString().contentEquals("null")) {
switch(key) {
case "forVehicleType":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.String"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("vehicleType", array.get(randomNumber));
} else {
actualRestrictions.put("vehicleType", jsonObject.get(key));
}
break;
case "forVehicleSize":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.String"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("vehicleSize", array.get(randomNumber));
} else {
actualRestrictions.put("vehicleSize", jsonObject.get(key));
}
break;
case "forVehicleConfiguration":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.String"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("vehicleConfiguration", array.get(randomNumber));
} else {
actualRestrictions.put("vehicleConfiguration", jsonObject.get(key));
}
break;
case "forVehicleAxles":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.Integer"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("noOfAxles", array.get(randomNumber));
} else {
actualRestrictions.put("noOfAxles", jsonObject.get(key));
}
break;
case "forEuVehicleCategory":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.String"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("euVehicleCategory", array.get(randomNumber));
} else {
actualRestrictions.put("euVehicleCategory", jsonObject.get(key));
}
break;
case "forVehicleClass":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.String"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("vehicleClass", array.get(randomNumber));
} else {
actualRestrictions.put("vehicleClass", jsonObject.get(key));
}
break;
case "forVehicleSubclass":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.String"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("vehicleSubclass", array.get(randomNumber));
} else {
actualRestrictions.put("vehicleSubclass", jsonObject.get(key));
}
break;
case "forVehicleWheels":
if (!(jsonObject.get(key).getClass().getName().contentEquals("java.lang.String"))) {
JSONArray array = (JSONArray) jsonObject.get(key);
Random r = new Random();
int randomNumber = r.nextInt(array.length());
actualRestrictions.put("numberOfWheelsDriven", array.get(randomNumber));
} else {
actualRestrictions.put("numberOfWheelsDriven", jsonObject.get(key));
}
break;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
return actualRestrictions;
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class VehicleTechnicalRecordsClient method createTechRecord.
public Map<String, Object> createTechRecord(String vehicleType) {
List<JsonPathAlteration> techRecordAlterations = new ArrayList<>();
String techRecordPayloadFile = "technical-records_" + vehicleType + ".json";
// CREATE TECH RECORD
Map<String, Object> testResultAttributes = new HashMap<>();
// generate random Vin
String randomVin = GenericData.generateRandomVin();
// generate random Vrm
String randomVrm = GenericData.generateRandomVrm();
if (!vehicleType.equals("hgv") && !vehicleType.equals("psv") && !vehicleType.equals("trl")) {
throw new AutomationException("Invalid vehicle type");
}
// read post request body from file
String postTechRecordBody = GenericData.readJsonValueFromFile(techRecordPayloadFile, "$");
// create alteration to change Vin in the request body with the random generated Vin
JsonPathAlteration alterationVin = new JsonPathAlteration("$.vin", randomVin, "", "REPLACE");
// create alteration to change primary vrm in the request body with the random generated primary vrm
JsonPathAlteration alterationVrm = new JsonPathAlteration("$.primaryVrm", randomVrm, "", "REPLACE");
// additional alterations for tech record
techRecordAlterations.add(alterationVin);
techRecordAlterations.add(alterationVrm);
// String alteredTechRecordBody = GenericData.applyJsonAlterations(postTechRecordBody, techRecordAlterations);
Response postTechRecordsResponse = postVehicleTechnicalRecordsWithAlterations(postTechRecordBody, techRecordAlterations);
// Response postTechRecordsResponse = given().filters(new BasePathFilter())
// .contentType(ContentType.JSON)
// .body(alteredTechRecordBody)
// .log().method().log().uri().log().body()
// .post("/vehicles");
//
// if (postTechRecordsResponse.getStatusCode() == 401 || postTechRecordsResponse.getStatusCode() == 403) {
// saveUtils();
// postTechRecordsResponse = given().filters(new BasePathFilter())
// .contentType(ContentType.JSON)
// .body(alteredTechRecordBody)
// .log().method().log().uri().log().body()
// .post("/vehicles");
// }
Assert.assertEquals(201, postTechRecordsResponse.getStatusCode());
Response getTechRecordsResponse = getVehicleTechnicalRecords(randomVin);
// Response getTechRecordsResponse = given().filters(new BasePathFilter())
// .contentType(ContentType.JSON)
// .pathParam("searchIdentifier", randomVin)
// .queryParam("status", "all")
// .queryParam("searchCriteria", "vin")
// .log().method().log().uri().log().body()
// .get("/vehicles/{searchIdentifier}/tech-records");
// if (getTechRecordsResponse.getStatusCode() == 401 || getTechRecordsResponse.getStatusCode() == 403) {
// getTechRecordsResponse = given().filters(new BasePathFilter())
// .contentType(ContentType.JSON)
// .pathParam("searchIdentifier", randomVin)
// .queryParam("status", "all")
// .queryParam("searchCriteria", "vin")
// .log().method().log().uri().log().body()
// .get("/vehicles/{searchIdentifier}/tech-records");
// }
// getTechRecordsResponse.prettyPrint();
Assert.assertEquals(getTechRecordsResponse.statusCode(), 200);
String systemNumber = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].systemNumber");
String trailerId;
String firstUseDate;
if (vehicleType.equals("trl")) {
trailerId = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].trailerId");
firstUseDate = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].firstUseDate");
} else {
trailerId = null;
firstUseDate = null;
}
int noOfAxles = GenericData.extractIntegerValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].noOfAxles");
String vehicleClassCode = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].vehicleClass.code");
String vehicleClassDescription = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].vehicleClass.description");
ArrayList<String> vehicleSubclass;
if (vehicleType.contentEquals("car") || vehicleType.contentEquals("lgv")) {
vehicleSubclass = GenericData.extractArrayListStringFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].vehicleSubclass");
} else {
vehicleSubclass = null;
}
String vehicleConfiguration;
if (!(vehicleType.contentEquals("car") || vehicleType.contentEquals("motorcycle") || vehicleType.contentEquals("lgv"))) {
vehicleConfiguration = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].vehicleConfiguration");
} else {
vehicleConfiguration = null;
}
String vehicleSize;
if (vehicleType.contentEquals("psv")) {
vehicleSize = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].vehicleSize");
} else {
vehicleSize = null;
}
String euVehicleCategory = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].euVehicleCategory");
String regnDate;
if (!vehicleType.contentEquals("trl")) {
regnDate = GenericData.extractStringValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].regnDate");
} else {
regnDate = null;
}
int numberOfWheelsDriven;
if (vehicleType.contentEquals("psv") || vehicleType.contentEquals("hgv") || vehicleType.contentEquals("motorcycle")) {
numberOfWheelsDriven = GenericData.extractIntegerValueFromJsonString(getTechRecordsResponse.prettyPrint(), "$[0].techRecord[0].numberOfWheelsDriven");
} else {
numberOfWheelsDriven = -1;
}
// add in map all attributes that we need to change in the test results payload so they match the values on the
// newly created tech record
testResultAttributes.put("vin", randomVin);
testResultAttributes.put("vrm", randomVrm);
testResultAttributes.put("systemNumber", systemNumber);
if (trailerId != null) {
testResultAttributes.put("trailerId", trailerId);
}
testResultAttributes.put("noOfAxles", noOfAxles);
testResultAttributes.put("vehicleClass.code", vehicleClassCode);
testResultAttributes.put("vehicleClass.description", vehicleClassDescription);
if (vehicleSubclass != null) {
testResultAttributes.put("vehicleSubclass", vehicleSubclass);
}
if (vehicleConfiguration != null) {
testResultAttributes.put("vehicleConfiguration", vehicleConfiguration);
}
if (vehicleSize != null) {
testResultAttributes.put("vehicleSize", vehicleSize);
}
testResultAttributes.put("euVehicleCategory", euVehicleCategory);
if (firstUseDate != null) {
testResultAttributes.put("firstUseDate", firstUseDate);
}
if (regnDate != null) {
testResultAttributes.put("regnDate", regnDate);
}
if (numberOfWheelsDriven != -1) {
testResultAttributes.put("numberOfWheelsDriven", numberOfWheelsDriven);
}
return testResultAttributes;
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class WebDriverBrowsertack method checkVsaEmailDetails.
public static void checkVsaEmailDetails(WebDriver driver, String randomVrm, String testName, String date) {
System.out.println("Checking the email title details are correct");
String actualString = driver.findElement(By.cssSelector("div[role='main']>div:nth-of-type(1)")).getText();
String expectedString = randomVrm + " " + testName + "|" + date + " (Certificate 1 of 1)";
try {
assertEquals(expectedString, actualString);
} catch (AssertionError e) {
throw new AutomationException("Actual string " + actualString + " does not contain expected string " + expectedString);
}
System.out.println("Checking the details in the email are correct");
String actualString1 = driver.findElement(By.cssSelector("div[role='main']>div:nth-of-type(2)")).getText();
String expectedString1 = "Please see the link below to access the test certificate for vehicle(s) " + randomVrm + " conducted on " + date;
try {
assertTrue(actualString1.contains(expectedString1));
} catch (AssertionError e) {
throw new AutomationException("Actual string '" + actualString1 + "' does not contain expected string '" + expectedString1 + "'");
}
driver.close();
driver.quit();
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class WebDriverBrowsertack method checkAtfEmail.
public static WebDriver checkAtfEmail(String testerName) {
WebDriverBrowsertack.setup();
FluentWait wait = new FluentWait<>(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofMillis(250)).ignoring(NoSuchElementException.class);
driver.get("https://outlook.live.com/owa/");
System.out.println("Going to microsoft login page");
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("nav.auxiliary-actions a[data-task='signin']")), ExpectedConditions.presenceOfElementLocated(By.cssSelector("nav.auxiliary-actions a[data-task='signin']"))));
driver.manage().window().maximize();
driver.findElement(By.cssSelector("nav.auxiliary-actions a[data-task='signin']")).click();
System.out.println("Filling in email address");
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='loginfmt']")), ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[name='loginfmt']"))));
driver.findElement(By.cssSelector("input[name='loginfmt']")).sendKeys(loader.getMicrosoftOnlineUserName());
driver.findElement(By.cssSelector("#idSIButton9")).click();
System.out.println("Filling in password");
try {
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']"))));
driver.findElement(By.cssSelector("input[name='passwd']")).sendKeys(loader.getMicrosoftOnlinePass());
driver.findElement(By.cssSelector("#idSIButton9")).click();
} catch (StaleElementReferenceException e) {
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']"))));
driver.findElement(By.cssSelector("input[name='passwd']")).sendKeys(loader.getMicrosoftOnlinePass());
driver.findElement(By.cssSelector("#idSIButton9")).click();
}
System.out.println("Confirming staying signed in");
int i = 0;
while (i < 5) {
if (driver.findElements(By.cssSelector("#idBtn_Back")).size() == 0) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
i++;
} else {
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#idBtn_Back")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("#idBtn_Back"))));
driver.findElement(By.cssSelector("#idSIButton9")).click();
break;
}
}
System.out.println("Searching for ATF email using tester name " + testerName);
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("[placeholder='Search']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("[placeholder='Search']"))));
driver.findElement(By.cssSelector("[placeholder='Search']")).sendKeys(testerName);
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
System.out.println("Confirming search returned at least one result");
i = 0;
while (i < 30) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!driver.findElement(By.cssSelector("div[aria-label='Message list']")).getText().contains("We didn't find anything.")) {
break;
}
driver.findElement(By.cssSelector("input[aria-label='Search']")).clear();
driver.findElement(By.cssSelector("input[aria-label='Search']")).sendKeys(testerName);
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
i++;
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
}
if (i == 30) {
System.out.println("Go to junk folder");
driver.findElement(By.cssSelector("div[title='Junk Email']")).click();
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("[name='Empty folder']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("[name='Empty folder']"))));
driver.findElement(By.cssSelector("input[aria-label='Search']")).clear();
driver.findElement(By.cssSelector("input[aria-label='Search']")).sendKeys(testerName);
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
int j = 0;
while (j < 120) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!driver.findElement(By.cssSelector("div[aria-label='Message list']")).getText().contains("We didn't find anything.")) {
break;
}
driver.findElement(By.cssSelector("input[aria-label='Search']")).clear();
driver.findElement(By.cssSelector("input[aria-label='Search']")).sendKeys(testerName);
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
j++;
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
}
if (j == 120) {
throw new AutomationException("Email was not found");
}
}
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("div[aria-label*='" + testerName + "']"), 0));
System.out.println("Select email that was searched for");
driver.findElements(By.cssSelector("div[aria-label*='" + testerName + "']")).get(0).click();
return driver;
}
use of exceptions.AutomationException in project cvs-auto-svc by dvsa.
the class WebDriverBrowsertack method checkVsaEmail.
public static WebDriver checkVsaEmail(String randomVrm) {
WebDriverBrowsertack.setup();
FluentWait wait = new FluentWait<>(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofMillis(250)).ignoring(NoSuchElementException.class);
driver.get("https://outlook.live.com/owa/");
System.out.println("Going to microsoft login page");
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("nav.auxiliary-actions a[data-task='signin']")), ExpectedConditions.presenceOfElementLocated(By.cssSelector("nav.auxiliary-actions a[data-task='signin']"))));
driver.manage().window().maximize();
driver.findElement(By.cssSelector("nav.auxiliary-actions a[data-task='signin']")).click();
System.out.println("Filling in email address");
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[name='loginfmt']")), ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[name='loginfmt']"))));
driver.findElement(By.cssSelector("input[name='loginfmt']")).sendKeys(loader.getMicrosoftOnlineUserName());
driver.findElement(By.cssSelector("#idSIButton9")).click();
System.out.println("Filling in password");
try {
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']"))));
driver.findElement(By.cssSelector("input[name='passwd']")).sendKeys(loader.getMicrosoftOnlinePass());
driver.findElement(By.cssSelector("#idSIButton9")).click();
} catch (StaleElementReferenceException e) {
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("input[name='passwd']"))));
driver.findElement(By.cssSelector("input[name='passwd']")).sendKeys(loader.getMicrosoftOnlinePass());
driver.findElement(By.cssSelector("#idSIButton9")).click();
}
System.out.println("Confirming staying signed in");
int i = 0;
while (i < 5) {
if (driver.findElements(By.cssSelector("#idBtn_Back")).size() == 0) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
i++;
} else {
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#idBtn_Back")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("#idBtn_Back"))));
driver.findElement(By.cssSelector("#idSIButton9")).click();
break;
}
}
System.out.println("Searching for VSA email using VRM " + randomVrm);
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("[placeholder='Search']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("[placeholder='Search']"))));
driver.findElement(By.cssSelector("#searchBoxId-Mail input")).clear();
driver.findElement(By.cssSelector("#searchBoxId-Mail input")).sendKeys(randomVrm);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
System.out.println("Confirming search returned at least one result");
i = 0;
while (i < 30) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!driver.findElement(By.cssSelector("div[aria-label='Message list']")).getText().contains("We didn't find anything.")) {
break;
}
driver.findElement(By.cssSelector("input[aria-label='Search']")).clear();
driver.findElement(By.cssSelector("input[aria-label='Search']")).sendKeys(randomVrm);
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
i++;
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
}
if (i == 30) {
System.out.println("Go to junk folder");
driver.findElement(By.cssSelector("div[title='Junk Email']")).click();
wait.until(ExpectedConditions.and(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("[name='Empty folder']")), ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("[name='Empty folder']"))));
driver.findElement(By.cssSelector("input[aria-label='Search']")).clear();
driver.findElement(By.cssSelector("input[aria-label='Search']")).sendKeys(randomVrm);
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
int j = 0;
while (j < 120) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!driver.findElement(By.cssSelector("div[aria-label='Message list']")).getText().contains("We didn't find anything.")) {
break;
}
driver.findElement(By.cssSelector("input[aria-label='Search']")).clear();
driver.findElement(By.cssSelector("input[aria-label='Search']")).sendKeys(randomVrm);
driver.findElement(By.cssSelector("button[aria-label='Search']")).click();
j++;
new WebDriverWait(driver, 1).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
}
if (j == 120) {
throw new AutomationException("Email was not found");
}
}
wait.until(ExpectedConditions.numberOfElementsToBeMoreThan(By.cssSelector("div[aria-label*='" + randomVrm + "']"), 0));
System.out.println("Select email that was searched for");
driver.findElements(By.cssSelector("div[aria-label*='" + randomVrm + "']")).get(0).click();
return driver;
}
Aggregations