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?
Music-Website/acceptanceTests/login.test.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (61 sloc)
2.21 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 puppeteer = require('puppeteer') | |
const { configureToMatchImageSnapshot } = require('jest-image-snapshot') | |
const PuppeteerHar = require('puppeteer-har') | |
const shell = require('shelljs') | |
const width = 800 | |
const height = 600 | |
const delayMS = 5 | |
let browser | |
let page | |
let har | |
// threshold is the difference in pixels before the snapshots dont match | |
const toMatchImageSnapshot = configureToMatchImageSnapshot({ | |
customDiffConfig: { threshold: 2 }, | |
noColors: true, | |
}) | |
expect.extend({ toMatchImageSnapshot }) | |
beforeAll( async() => { | |
browser = await puppeteer.launch({ headless: true, slowMo: delayMS, args: [`--window-size=${width},${height}`] }) | |
page = await browser.newPage() | |
har = new PuppeteerHar(page) | |
await page.setViewport({ width, height }) | |
await shell.exec('acceptanceTests/scripts/beforeAll.sh') | |
}) | |
afterAll( async() => { | |
browser.close() | |
await shell.exec('acceptanceTests/scripts/afterAll.sh') | |
}) | |
beforeEach(async() => { | |
await shell.exec('acceptanceTests/scripts/beforeEach.sh') | |
}) | |
describe('Registering', () => { | |
test('Register a user', async done => { | |
//start generating a trace file. | |
await page.tracing.start({path: 'trace/registering_user_har.json',screenshots: true}) | |
await har.start({path: 'trace/registering_user_trace.har'}) | |
//ARRANGE | |
await page.goto('http://localhost:8080/register', { timeout: 30000, waitUntil: 'load' }) | |
//ACT | |
await page.type('input[name=user]', 'NewUser') | |
await page.type('input[name=pass]', 'password') | |
await page.click('input[type=submit]') | |
await page.goto('http://localhost:8080/login', { timeout: 30000, waitUntil: 'load' }) | |
await page.type('input[name=user]', 'NewUser') | |
await page.type('input[name=pass]', 'password') | |
await page.click('input[type=submit]') | |
//ASSERT | |
//check that the user is taken to the homepage after attempting to login as the new user: | |
await page.waitForSelector('h1') | |
expect( await page.evaluate( () => document.querySelector('h1').innerText ) ) | |
.toBe('Home') | |
// grab a screenshot | |
const image = await page.screenshot() | |
// compare to the screenshot from the previous test run | |
expect(image).toMatchImageSnapshot() | |
// stop logging to the trace files | |
await page.tracing.stop() | |
await har.stop() | |
done() | |
}, 16000) | |
}) |