Created
November 3, 2019 00:57
-
-
Save ivanvanderbyl/cf384ae336e3b5364d211f22e6d42bb7 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 { expect } = require('chai'); | |
describe('Duck Duck Go search using basic Puppeteer', () => { | |
let browser; | |
let page; | |
beforeEach(async () => { | |
browser = await puppeteer.launch(); | |
page = await browser.newPage(); | |
await page.goto('https://duckduckgo.com'); | |
}); | |
afterEach(async () => { | |
await browser.close(); | |
}); | |
it('should have the correct page title', async () => { | |
expect(await page.title()).to.eql('DuckDuckGo — Privacy, simplified.'); | |
}); | |
it('should show a list of results when searching actual word', async () => { | |
await page.type('input[id=search_form_input_homepage]', 'puppeteer'); | |
await page.click('input[type="submit"]'); | |
await page.waitForSelector('h2 a'); | |
const links = await page.evaluate(() => { | |
return Array.from(document.querySelectorAll('h2 a')); | |
}); | |
expect(links.length).to.be.greaterThan(0); | |
}); | |
it('should show a warning when searching fake word', async () => { | |
await page.type('input[id=search_form_input_homepage]', 'pupuppeppeteerteer'); | |
await page.click('input[type="submit"]'); | |
await page.waitForSelector('div[class=msg__wrap]'); | |
const text = await page.evaluate(() => { | |
return document.querySelector('div[class=msg__wrap]').textContent; | |
}); | |
expect(text).to.contain('Not many results contain'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment