Skip to content

Instantly share code, notes, and snippets.

@ivanvanderbyl
Created November 3, 2019 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ivanvanderbyl/cf384ae336e3b5364d211f22e6d42bb7 to your computer and use it in GitHub Desktop.
Save ivanvanderbyl/cf384ae336e3b5364d211f22e6d42bb7 to your computer and use it in GitHub Desktop.
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