Skip to content

Instantly share code, notes, and snippets.

import { PlaywrightTestConfig } from '@playwright/test';
import { devices } from 'playwright';
import dotenv from 'dotenv';
dotenv.config();
export const storageStatePath = 'storage-state/storageState.json';
const config: PlaywrightTestConfig = {
use: {
import { test as setup } from '@playwright/test';
import { storageStatePath } from './playwright.config';
const username = process.env.MEETUP_USERNAME ?? '';
const password = process.env.MEETUP_PASSWORD ?? '';
setup('Login a user', async ({ page }) => {
await page.goto('https://www.meetup.com/login');
await page.getByLabel('Email').fill(username);
await page.getByLabel('Password', { exact: true }).fill(password);
import { test as setup } from '@playwright/test';
import { storageStatePath } from './playwright.config';
const username = process.env.MEETUP_USERNAME ?? '';
const password = process.env.MEETUP_PASSWORD ?? '';
setup('Login a user', async ({ page }) => {
await page.goto('https://www.meetup.com/login');
await page.getByLabel('Email').fill(username);
await page.getByLabel('Password', { exact: true }).fill(password);
import { test, expect } from '@playwright/test';
test('example test', async ({ page }) => {
await page.goto('http://localhost:3000');
await page.waitForLoadState('networkidle');
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.02,
mask: [page.locator('data-test-id=random-game-image')],
});
});
import { test, expect } from '@playwright/test';
test('example test', async ({ page }) => {
await page.goto('http://localhost:3000');
await page.waitForLoadState('networkidle');
await expect(page).toHaveScreenshot({ maxDiffPixelRatio: 0.02 });
});
<img data-test-id="random-game-image" src="https://api.lorem.space/image/game?w=250" alt="random-game-poster"/>
import { test, expect } from '@playwright/test';
test('example test', async ({ page }) => {
await page.goto('http://localhost:3000');
await expect(page).toHaveScreenshot({ maxDiffPixelRatio: 0.02 });
});
import { test, expect } from '@playwright/test';
test('example test', async ({ page }) => {
await page.goto('http://localhost:3000');
await expect(page).toHaveScreenshot();
});
import { expect, test } from '@playwright/test';
test('Navigate to notifications', async ({ page }) => {
await page.goto('https://www.meetup.com/notifications');
await expect(page.locator(`"Nothing here yet"`).first()).toBeVisible();
});
test('Navigate to payment methods', async ({ page }) => {
await page.goto('https://www.meetup.com/account/payment-methods');
await expect(page.locator(`"You don't have any saved cards."`).first()).toBeVisible();
const config: PlaywrightTestConfig = {
globalSetup: './global-setup',
use: {
storageState: 'storage-state/storageState.json',
},
};