Мой тест проверяет, что билет был куплен и отправлен на мою учетную запись Gmail. Я всегда получаю 2 письма за 1 покупку, проверяю оба на наличие необходимого заголовка и тела. Этот код работал, но теперь он не работает все время, когда я его запускаю.
@SneakyThrows
public static void verifyTicketPurchasedEmailReceived(User emailUser, String username, String registeredUserEmail, int emailCount, Date testStartTime) {
final String[] emailBodyText = {""};
WebDriverWait webDriverWait = new WebDriverWait(getWebDriver(), 100, 40000);
webDriverWait.ignoring(MessagingException.class);
webDriverWait.until(d -> {
List<Email> receivedEmails = EmailService.getEmails(emailUser.getEmail(), emailUser.getPassword(), emailCount, testStartTime);
for (Email receivedEmail : receivedEmails) {
if (receivedEmail.getTitle().contains("Your TICKET")) {
if (receivedEmail.getBody().contains("Thank you for purchasing a ticket to our upcoming event:")) {
emailBodyText[0] = receivedEmail.getBody();
}
}
}
return emailBodyText[0].contains("Dearest " + username + ",");
});
verifyRequiredData(username, registeredUserEmail, emailBodyText[0]);
}
private static void verifyRequiredData(String username, String registeredUserEmail, String emailBody) {
String greeting = "Dearest " + username + ",";
Assert.assertTrue("Email does not contain " + greeting, emailBody.contains(greeting));
Assert.assertTrue("Email does not contain " + registeredUserEmail, emailBody.contains(registeredUserEmail));
Assert.assertTrue("Email does not contain redirection URL", emailBody.contains("ct.sendgrid.net/wf/click"));
}
Ошибка:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for Actions.AbstractActions.GmailEmailActions$$Lambda$245/1541427914@ab24484 (tried for 100 second(s) with 40000 milliseconds interval)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-VQ56FMV', ip: '192.168.0.178', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.116, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: C:\Users\Nastya\AppData\Loc...}, goog:chromeOptions: {debuggerAddress: localhost:57101}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: d16876aa4c55ff1a92d94841ed7...}