-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jack-mailslurp
committed
Nov 26, 2024
1 parent
0d8ffb7
commit c6982e1
Showing
6 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Playwright low-code example | ||
Test user sign-up and email verification flow using the low-code MailSlurp [test interface](https://test.mailslurp.com). | ||
|
||
## Setup | ||
|
||
Set the `API_KEY` environment variable to your [MailSlurp API KEY](https://app.mailslurp.com) value. | ||
|
||
### Setting the `API_KEY` Environment Variable | ||
|
||
#### Visual Studio Code | ||
1. Open the command palette (`Ctrl+Shift+P` or `Cmd+Shift+P`). | ||
2. Search for `Preferences: Open Settings (UI)`. | ||
3. In the search bar, type `env`. | ||
4. Click on `Edit in settings.json`. | ||
5. Add the following line to your `settings.json` file: | ||
```json | ||
"terminal.integrated.env.osx": { | ||
"API_KEY": "your-mailslurp-api-key" | ||
}, | ||
"terminal.integrated.env.linux": { | ||
"API_KEY": "your-mailslurp-api-key" | ||
}, | ||
"terminal.integrated.env.windows": { | ||
"API_KEY": "your-mailslurp-api-key" | ||
} | ||
``` | ||
|
||
#### Terminal | ||
- **Mac/Linux:** | ||
```sh | ||
export API_KEY=your-mailslurp-api-key | ||
``` | ||
- **Windows (Command Prompt):** | ||
```cmd | ||
set API_KEY=your-mailslurp-api-key | ||
``` | ||
- **Windows (PowerShell):** | ||
```powershell | ||
$env:API_KEY="your-mailslurp-api-key" | ||
``` | ||
|
||
#### Playwright Configuration | ||
Add the following to your `playwright.config.ts` or `playwright.config.js`: | ||
```javascript | ||
// playwright.config.ts or playwright.config.js | ||
import { defineConfig } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
use: { | ||
env: { | ||
API_KEY: process.env.API_KEY || 'your-mailslurp-api-key', | ||
}, | ||
}, | ||
}); | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "pwt", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"devDependencies": { | ||
"@playwright/test": "^1.49.0", | ||
"@types/node": "^22.10.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
permissions: ['clipboard-read'], | ||
headless: false | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test('test using test.mailslurp.com', async ({ page, context }) => { | ||
const password = 'test-password'; | ||
const apiKey = process.env.API_KEY; | ||
expect(apiKey, 'API_KEY environment variable should be set').toBeTruthy() | ||
await context.grantPermissions(["clipboard-read", "clipboard-write"]); | ||
await page.goto('https://test.mailslurp.com/?emailId='); | ||
await page.getByTestId('api-key').click(); | ||
await page.getByTestId('api-key').click(); | ||
await page.getByTestId('api-key').fill(apiKey); | ||
await page.getByTestId('submit').click(); | ||
await page.getByTestId('copy-email').click(); | ||
const emailAddress = await page.evaluate(() => navigator.clipboard.readText()); | ||
await page.goto('https://api.mailslurp.com/test-application/sign-up'); | ||
await page.getByPlaceholder('[email protected]').click(); | ||
await page.getByPlaceholder('[email protected]').fill(emailAddress); | ||
await page.getByPlaceholder('Password').click(); | ||
await page.getByPlaceholder('Password').fill(password); | ||
await page.getByTestId('submit').click(); | ||
await page.goto('https://test.mailslurp.com/?emailId='); | ||
await page.getByTestId('email-0').click(); | ||
await page.getByTestId('tab-codes').click(); | ||
await page.getByTestId('regex-input').click(); | ||
await page.getByTestId('regex-input').fill('is "(.+)"'); | ||
await page.getByTestId('submit-regex').click(); | ||
await page.locator('div').filter({ hasText: /^1\[data-testid="match-item-1"\]\[data-testid="match-item-1"\]$/ }).getByRole('button').click(); | ||
const code = await page.evaluate(() => navigator.clipboard.readText()); | ||
|
||
await page.goto('https://api.mailslurp.com/test-application/confirm'); | ||
await page.getByPlaceholder('Code').click(); | ||
await page.getByPlaceholder('Code').fill(code); | ||
await page.getByPlaceholder('[email protected]').click(); | ||
await page.getByPlaceholder('[email protected]').fill(emailAddress); | ||
await page.getByTestId('submit').click(); | ||
await page.getByPlaceholder('[email protected]').click(); | ||
await page.getByPlaceholder('[email protected]').fill(emailAddress); | ||
await page.getByPlaceholder('Password').click(); | ||
await page.getByPlaceholder('Password').fill(password); | ||
await page.getByTestId('submit').click(); | ||
await expect(page.getByText('It all looks strawberry!')).toBeVisible(); | ||
}); |