Untitled
unknown
plain_text
a year ago
2.4 kB
14
Indexable
public String RetrieveCodeFromLastBREMail() throws Exception {
Thread.sleep(50000);
Extent.getTest().info("Waiting to click on the BRE Email...");
System.out.println("In ProtonMail tab, waiting to click on the BRE Email");
WAITFORVISIBLEELEMENT(driver, lastBreEmail);
CLICK(lastBreEmail, "BRE Email is clicked");
// Debug the iframe structure
List<WebElement> elements = driver.findElements(By.tagName("iframe"));
System.out.println("Total iframes: " + elements.size());
for (WebElement element : elements) {
System.out.println("Iframe Name: " + element.getAttribute("name") + ", ID: " + element.getAttribute("id"));
Extent.getTest().info("Iframe Name: " + element.getAttribute("name"));
}
// Switch to the correct iframe using the name or ID (replace accordingly)
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
WebElement iframeElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("assistant-iframe"))); // Adjust with correct iframe name or id
driver.switchTo().frame(1);
System.out.println("Switched to iFrame");
WebElement elementInsideIframe = driver.findElement(By.xpath("//span[contains(text(), 'Your code is')]"));
String emailBodyText = GETTEXT(elementInsideIframe);
System.out.println("Verification code is:" + breEmailBodyText);
Extent.getTest().info("Extracted text from the email... " + breEmailBodyText);
// Extract the text from the email body
System.out.println("Extracted text from the email: " + emailBodyText);
Extent.getTest().info("Extracted text from the email...");
// Use regex to extract the six-digit verification code
Pattern pattern = Pattern.compile("Your code is:\\s*(\\d{6})");
Matcher matcher = pattern.matcher(emailBodyText);
if (matcher.find()) {
String verificationCode = matcher.group(1); // The 6-digit code
System.out.println("Verification Code is: " + verificationCode);
Extent.getTest().info("Verification code is: " + verificationCode);
driver.switchTo().defaultContent();
return verificationCode; // Return the extracted code
} else {
Extent.getTest().info("Verification code is not found in the email body");
throw new Exception("Verification code not found in the email body.");
}
}Editor is loading...
Leave a Comment