Skip to content

Instantly share code, notes, and snippets.

@dmitrika
Last active September 4, 2019 10:21
Show Gist options
  • Save dmitrika/7dee618842c00fbc35418b901735656b to your computer and use it in GitHub Desktop.
Save dmitrika/7dee618842c00fbc35418b901735656b to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer');
const { defineSupportCode } = require('cucumber')
defineSupportCode(({ Before, Given, When, Then }) => {
Before({ timeout: 60 * 1000 }, async function testCase() {
this.browser = await puppeteer.launch()
})
Given('I am on google with puppeteer', { timeout: 60 * 1000 }, async function testCase() {
this.page = await this.browser.newPage()
await this.page.goto('https://google.com')
})
When('I enter {string}', async function testCase(text) {
await this.page.waitFor('input[name=q]')
await this.page.type('input[name=q]', text)
await this.page.click('input[type="submit"]')
})
Then('I should see {string}', async function testCase(text) {
await this.page.waitForSelector('h3 a')
const links = await this.page.evaluate(() => {
const anchors = Array.from(document.querySelectorAll('h3 a'))
return anchors.map(anchor => anchor.textContent)
})
console.log(links.join('\n'))
console.log(text)
await this.browser.close()
})
})
@GabrielCzar
Copy link

Change the file extension to .js for better visualization with github highlighting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment