使用JavaMail API等待新电子邮件
我必须测试邮件是否发送到某个电子邮件。我已经写了一些代码来阅读电子邮件。现在我需要编写代码,直到收到消息,然后再读取消息,因为有些测试用例失败,而消息没有立即发送。我正在使用JavaMail API。下面是我使用和中的信息编写的代码 但这似乎不起作用使用JavaMail API等待新电子邮件,java,selenium,jakarta-mail,qa,browser-automation,Java,Selenium,Jakarta Mail,Qa,Browser Automation,我必须测试邮件是否发送到某个电子邮件。我已经写了一些代码来阅读电子邮件。现在我需要编写代码,直到收到消息,然后再读取消息,因为有些测试用例失败,而消息没有立即发送。我正在使用JavaMail API。下面是我使用和中的信息编写的代码 但这似乎不起作用 public void waitUntilNewEmailIsReceived() { try { ExecutorService es = Executors.newCachedThreadPool
public void waitUntilNewEmailIsReceived() {
try {
ExecutorService es = Executors.newCachedThreadPool();
final IdleManager idleManager = new IdleManager(session, es);
inbox.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
isNewMessagesReceived = true;
}
});
idleManager.watch(inbox);
} catch (IOException | MessagingException e) {
isNewMessagesReceived = false;
System.err.println(e.printStackTrace();
}
}