HomeAPI and SDKs Testing E-Mails Testing E-Mails Test programmatically whether emails are correctly sent from a web application or mobile app.
For email testing in the webmate web app, see Testing Mails
.
Incomplete: Not all snippets available in this language yet! Coming soon!
You need an authenticated webmateSession to call this function, see this article
on how to set up and authenticate with the SDK.
First you need to create the temporary email address to use as receiver for your test mails.
1
2
3
4
WebmateSeleniumSession webmateSeleniumSession = webmateSession.addSeleniumSession (driver.getSessionId .toString );
TestRunId testRunId = webmateSeleniumSession.getTestRunId ();
TestMailAddress mailAddress = webmateSession.mailTest .createTestMailAddress ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId);
You need an authenticated webmateSession to call this function, see this article
on how to set up and authenticate with the SDK.
First you need to create the temporary email address to use as receiver for your test mails.
1
2
let testRunId = webmateSession .addSeleniumSession (browserObj .sessionId ).getTestRunId ();
let mailAddress = await webmateSession .mailTest .createTestMailAddress ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId ).toPromise ();
After triggering the emails in your application, you can fetch the received emails:
Incomplete: Not all snippets available in this language yet! Coming soon!
1
List< TestMail> mails = webmateSession.mailTest .getMailsInTestRun ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId)
The webmate TestMail class offers the following methods for checking if the correct mails were received:
1
let mails = await webmateSession .mailTest .getMailsInTestRun ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId ).toPromise ();
The webmate TestMail class offers the following variables for checking the mail content:
Incomplete: Not all snippets available in this language yet! Coming soon!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static void waitUntilNumMailsAvailable (WebmateAPISession webmateSession, TestRunId testRunId, Integer numMails, long interval, WebDriver driver) {
List< TestMail> mails = webmateSession.mailTest .getMailsInTestRun ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId);
long start = System.currentTimeMillis ();
long end = start + TestConfig.MAIL_RECEIVE_TIMEOUT * 1000;
System.out .println ("Wait for an email to be received" );
while (mails.size () < numMails + 1 && System.currentTimeMillis () < end) {
try {
Thread.sleep (interval);
mails = webmateSession.mailTest .getMailsInTestRun ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId);
// make sure the session does not timeout
String currentWindow = driver.getWindowHandle ();
driver.switchTo ().window (currentWindow);
} catch (Exception e) {
continue ;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
async function waitUntilNumMailsAvailable (WebmateAPISession webmateSession , TestRunId testRunId , var numMails , var interval , BrowserObject driver ) {
let mails = await webmateSession .mailTest .getMailsInTestRun ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId ).toPromise ();
var start = Date.now ();
var end = start + TestConfig .MAIL_RECEIVE_TIMEOUT * 1000 ;
console .log ("Wait for an email to be received" );
while (mails .size () < numMails + 1 && Date.now () < end ) {
try {
await new Promise (resolve => setTimeout (resolve , interval ));
await webmateSession .mailTest .getMailsInTestRun ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId ).toPromise ();
// make sure the session does not timeout
let currentWindow = driver .getWindowHandle ();
driver .switchToWindow (currentWindow );
} catch (err ) {
continue ;
}
}
}
Incomplete: Not all snippets available in this language yet! Coming soon!
1
2
3
WebmateSeleniumSession seleniumSession = webmateSession.addSeleniumSession (driver.getSessionId ().toString ());
TestMailAddress testMailAddress = webmateSession.mailTest .createTestMailAddress (WebmateCredentials.MY_WEBMATE_PROJECTID , seleniumSession.getTestRunId ());
waitForElement(driver, By.id ("customer-email" )).sendKeys (testMailAddress.getAddress ());
1
2
3
4
5
let testRunId = webmateSession .addSeleniumSession (browserObj .sessionId ).getTestRunId ();
let mailAddress = await webmateSession .mailTest .createTestMailAddress ("7c4f09fd-xxx-xxx-xxx-xxx" , testRunId ).toPromise ();
let mailInput = await browserObj .$ ("#customer-email" );
await mailInput .waitForExist ();
element (by .id ('customer-email' )).sendKeys (testMailAddress );
Last update on 23 June 2021
3 min read