Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
TEACHING-MATERIALS/exercises/05_advanced_testing/02_acceptance/spec/form.spec.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
58 lines (51 sloc)
1.5 KB
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
'use strict' | |
const faker = require('faker') | |
const puppeteer = require('puppeteer') | |
const lead = { | |
name: faker.name.firstName(), | |
email: faker.internet.email(), | |
phone: faker.phone.phoneNumber(), | |
message: faker.random.words() | |
} | |
let page | |
let browser | |
const width = 800 | |
const height = 600 | |
beforeAll( async() => { | |
browser = await puppeteer.launch({ | |
headless: true, | |
slowMo: 40, | |
args: [`--window-size=${width},${height}`, '--disable-http2'] | |
}) | |
page = await browser.newPage() | |
await page.setViewport({ width, height }) | |
}) | |
// afterAll(() => { | |
// browser.close() | |
// }) | |
describe('Shopping List', () => { | |
test('can add a single item', async done => { | |
await page.waitFor(1000) | |
await page.tracing.start({path: 'trace.json',screenshots: true}) | |
await page.goto('http://localhost:8080/', { waitUntil: 'domcontentloaded' }) | |
await page.waitForSelector('input[name=item]') | |
await page.click('input[name=item]') | |
await page.type('input[name=item]', 'bread') | |
await page.click('input[name=qty]') | |
await page.type('input[name=qty]', '42') | |
await page.click('input[type=submit]') | |
await page.waitFor(1000) | |
await page.screenshot({ path: 'screenshots/page.png' }) | |
const title = await page.title() | |
expect(title).toBe('ToDo List') | |
const data = await page.evaluate(() => { | |
const tds = Array.from(document.querySelectorAll('table tr td:first-child')) | |
return tds.map(td => td.innerHTML) | |
}) | |
console.log(data) | |
expect(data.length).toBe(1) | |
await page.tracing.stop() | |
await browser.close() | |
done() | |
}, 16000) | |
}) |