Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne jasonbyrne/npmjs.js
Created Sep 5, 2019

Embed
What would you like to do?
Flagpole suite with Puppeteer
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
You can’t perform that action at this time.