Skip to content

Instantly share code, notes, and snippets.

View MarcusFelling's full-sized avatar

Marcus Felling MarcusFelling

View GitHub Profile
// Throw Error: Path is not available when connecting remotely. Use saveAs() to save a local copy.
import { test, expect } from '@playwright/test';
import fs from 'fs';
test('download result', async ({ page }) => {
await page.goto('https://demo.playwright.dev/svgomg');
await page.locator('.menu-item >> text=Demo').click();
const downloadButton = page.locator('a[title=Download]');
await expect(downloadButton).toHaveAttribute('href', /blob/);
const [download] = await Promise.all([
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
use: {
baseURL: 'http://localhost:3000/',
},
projects: [
// Setup project
{
name: 'setup',
import { test as setup } from '@playwright/test';
const authFile = '.auth/user.json';
setup('authenticate', async ({ page }) => {
// skip setup if environment variables for AAD creds are not set
setup.skip(!process.env.AADUSERNAME || !process.env.AADPASSWORD, 'AADUSERNAME and AADPASSWORD environment variables must be set');
await page.goto('');
// Sign in using creds from env variables
// Use try catch block to handle the case where the consent dialog is shown for first login
try {
await dialog.waitForURL('**/Consent/**');
await dialog.getByRole('button', { name: 'Yes' }).click();
} catch (e) {
// Consent dialog was not shown
}
import { test, expect, Page, TestInfo } from '@playwright/test';
test('performance test example', async ({ page }, TestInfo) => {
// Perform actions
await page.goto(`/`);
// Measure performance
await measurePerformance(page, TestInfo);
});
async function measurePerformance(page: Page, TestInfo: TestInfo) {
async function measureCartPerformance(page: Page, TestInfo: TestInfo) {
// Navigate to shopping cart
await page.goto(`/Carts`);
// Use Performance API to measure performance
// https://developer.mozilla.org/en-US/docs/Web/API/Performance/getEntriesByType
const performance = await page.evaluate(() => performance.getEntriesByType('navigation'));
// Get the first entry
const performanceTiming = performance[0];
// Get the start to load event end time
const startToLoadEventEnd = performanceTiming.loadEventEnd - performanceTiming.startTime;
jobs:
staging:
uses: ./.github/workflows/template.yml
secrets: inherit
with:
environmentName: staging
production:
needs: staging
uses: ./.github/workflows/template.yml
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
projects: [
// Setup project
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
// Test project that requires authentication
{
name: 'authenticated',
testMatch: /.authtests\.ts/,
import { test as setup } from '@playwright/test';
const authFile = '.auth/user.json';
setup('authenticate', async ({ browser }) => {
const page = await browser.newPage();
await page.goto('');
// Sign in using creds from env variables
const dialogPromise = page.waitForEvent('popup');
await page.getByText('LOGIN').click();