Skip to content

Instantly share code, notes, and snippets.

@ryanrosello-og
ryanrosello-og / xstate playwright example.ts
Created July 15, 2022 11:35
xstate + playwright example
import { test, expect, Page } from '@playwright/test';
import { createMachine } from 'xstate';
import { createModel } from '@xstate/test';
let page: Page;
test.describe('Playwright document search', () => {
const documentationSearchMachine = createMachine({
id: 'documentSearch',
initial: 'idle',
states: {
@ryanrosello-og
ryanrosello-og / validate a complex pdf using Playwright.ts
Last active July 10, 2022 10:28
validate a complex pdf using Playwright
import {test, expect} from '@playwright/test';
test('validate a complex pdf II, all pages', async ({page}) => {
const numberOfPages = 2;
for (let i = 1; i < numberOfPages + 1; i += 1) {
let pdfResource =
'https://oedtrngbj.wpengine.com/wp-content/uploads/Powerwall_2_AC_Datasheet_EN_NA.pdf';
let iframe = `<iframe src="${pdfResource}#zoom=60&page=${i}" style="width: 100%;height:100%;border: none;"></iframe>`;
await page.setContent(iframe);
await page.waitForTimeout(5000);
@ryanrosello-og
ryanrosello-og / Playwright VSCode Launch Profile.json
Last active July 9, 2022 11:14
Playwright VSCode Launch Profile
// package.json
{
"name": "fancy_vscode_launch_profiles",
"version": "1.0.0",
"scripts": {
"vscode-debug": "playwright test --config ./playwright.config.ts --workers=1"
},
"devDependencies": {
"@playwright/test": "^1.22.2"
@ryanrosello-og
ryanrosello-og / assert PDF contents using Playwright.ts
Created July 8, 2022 10:29
assert PDF contents using Playwright
import PDFParser from 'pdf2json';
import { test, expect } from '@playwright/test';
test.describe('assert PDF contents using Playwright', () => {
let pdfContents: any
test.beforeAll(async () => {
pdfContents = await getPDFContents('./pdf_sample.pdf')
})
test('pdf file should have 6 pages', async () => {
@ryanrosello-og
ryanrosello-og / Use playwright to download files from remote servers.ts
Created July 8, 2022 08:39
Use playwright to download files from remote servers
import { test, expect } from '@playwright/test';
import * as fs from 'fs/promises'
test.describe('use Playwright to easliy download a file from remote server', () => {
test('able to download a remote file to disk', async ({ page }, testInfo) => {
const baseUrl = 'https://www.tesla.com/'
const resource = 'ns_videos/2021-tesla-impact-report.pdf'
const getResp = await page.context().request.get(`${baseUrl}${resource}`)
expect(getResp.ok()).toBe(true)