-
-
Save yakup/4f80eaebfa6858f66bf0300fb258fd89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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() | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment