MailFlatDocs
Documentation/Test frameworks & CI/WebdriverIO

Using MailFlat with WebdriverIO

Hooks in wdio.conf.js open and close the inbox; the spec just reads the address off the global.

How it fits together

WebdriverIO's config file already owns the test lifecycle, so the inbox belongs there too: beforeTest opens one, afterTest deletes it.

The hooks

JavaScript
// wdio.conf.js
const { MailFlat } = require("@mailflat/sdk");
const mf = new MailFlat({ apiKey: process.env.MAILFLAT_API_KEY });
 
exports.config = {
async beforeTest() {
global.inbox = await mf.create({
prefix: `wdio-${Date.now().toString(36)}`,
retentionHours: 2,
});
},
async afterTest() {
await global.inbox?.delete();
},
};

The spec

JavaScript
// test/specs/signup.e2e.js
describe("signup", () => {
it("accepts a real verification code", async () => {
await browser.url("/signup");
await $("#email").setValue(global.inbox.address);
await $("#submit").click();
 
await $("#code").setValue(await global.inbox.waitForOtp({ timeout: 60000 }));
await expect(browser).toHaveUrl(expect.stringContaining("/dashboard"));
});
});

Worth knowing

WebdriverIO's own waitUntil is for the browser. Use waitForOtp for the mailbox — it polls the API, not the DOM.