https://github.com/mailslurp/examples
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
const config: PlaywrightTestConfig = {
testDir: './tests',
timeout: 30 * 1000,
expect: {
timeout: 5000
},
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
actionTimeout: 0,
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
video: 'on'
},
}
]
};
export default config;
{
"name": "playwright-email-testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.22.2"
},
"dependencies": {
"mailslurp-client": "^15.9.0"
}
}
-include ../.env
.PHONY: test
node_modules:
npm install
test: node_modules
API_KEY=$(API_KEY) npx playwright test
//<gen>playwright_email_testing_full
import { test, expect, Page } from '@playwright/test';
import MailSlurp from "mailslurp-client";
test.describe('test email login with playwright', () => {
test('can login and verify email address with mailslurp', async ({ page }) => {
const apiKey = process.env.API_KEY;
expect(apiKey).toBeDefined();
// load playground app
await page.goto("https://playground.mailslurp.com");
await page.click('[data-test="sign-in-create-account-link"]');
// create a new inbox
const mailslurp = new MailSlurp({ apiKey })
const password = "test-password"
const { id, emailAddress } = await mailslurp.createInbox()
// fill sign up form
await page.fill('input[name=email]', emailAddress);
await page.fill('input[name=password]', password);
await page.click('[data-test="sign-up-create-account-button"]');
// wait for verification code
const email = await mailslurp.waitForLatestEmail(id)
// extract the confirmation code (so we can confirm the user)
const code = /([0-9]{6})$/.exec(email.body)[1];
// enter confirmation code
await page.fill('[data-test="confirm-sign-up-confirmation-code-input"]', code);
await page.click('[data-test="confirm-sign-up-confirm-button"]');
// fill out username (email) and password
await page.fill('[data-test="username-input"]', emailAddress);
await page.fill('[data-test="sign-in-password-input"]', password);
// submit
await page.click('[data-test="sign-in-sign-in-button"]');
await page.waitForSelector("[data-test='greetings-nav']")
});
});
//</gen>