Created
September 5, 2019 05:34
-
-
Save jasonbyrne/45c5bf14046e25f984a530d93b4c07e8 to your computer and use it in GitHub Desktop.
Flagpole suite with Puppeteer
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
const { Flagpole } = require('flagpole'); | |
const opts = { | |
headless: false, | |
width: 1280, | |
height: 600 | |
}; | |
const suite = Flagpole.suite('Basic Smoke Test of npmjs.com') | |
.base('https://www.npmjs.com/'); | |
suite.browser("Search for Flagpole", opts) | |
.open("/") | |
.next('Verify homepage looks valid', async context => { | |
const heroContents = await context.waitForExists('#hero_contents'); | |
const h1 = await heroContents.find('h1'); | |
const cta = await heroContents.find('a[href="/products/"]'); | |
context.assert(h1).exists(); | |
context.assert(await h1.getText()).like('build amazing things'); | |
context.assert(cta).exists(); | |
context.assert(await cta.getText()).equals('See plans'); | |
}) | |
.next('Fill out the search box and submit', async context => { | |
const form = await context.find('form#search'); | |
context.assert(form).exists(); | |
const input = await form.find('input[name="q"]'); | |
context.assert(input).exists(); | |
await input.type('Flagpole'); | |
context.assert(await input.getValue()).equals('Flagpole'); | |
return form.submit(); | |
}) | |
.next('Validate search results page', async context => { | |
await context.waitForNavigation(); | |
const main = await context.waitForExists('main'); | |
const heading = await main.find('h2'); | |
const searchResults = await main.findAll('section'); | |
context.assert(await heading.getText()) | |
.contains('packages found'); | |
context.assert('Should be search results', searchResults) | |
.length.greaterThan(0); | |
return searchResults[0]; | |
}) | |
.next('First result should be Flagpole', async context => { | |
const firstResult = await context.result; | |
const title = await firstResult.find('h3'); | |
const link = await title.getParent(); | |
context.assert('Found search result title', title).exists(); | |
context.assert( | |
'Title should say exactly flagpole', | |
await title.getText() | |
).exactly('flagpole'); | |
context.assert('Parent of title should exist', link) | |
.exists(); | |
context.assert( | |
'Parent of title should be an <a> tag', | |
await link.getTagName() | |
).equals('a'); | |
context.assert( | |
'Href should link to flagpole package', | |
await link.getAttribute('href') | |
).contains('/package/flagpole'); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment