Created
April 10, 2020 18:17
-
-
Save jaffamonkey/27c5fbf7667487aafd8105d691166b28 to your computer and use it in GitHub Desktop.
This file contains 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
// Filename: mocha-chai-nightmare.js | |
// To setup: npm install -g mocha chai nightmare | |
// To run: mocha mocha-chai-nightmare.js | |
const Nightmare = require('nightmare'); | |
let assert = require('chai').assert; | |
describe('Check the DuckDuckGo search results page title', function () { | |
this.timeout('60s'); | |
//before each test, | |
beforeEach(function (done) { | |
nightmare = Nightmare({ | |
show: false | |
}); | |
done(); | |
}); | |
it('should show correct results page title', function (done) { | |
nightmare.goto('https://duckduckgo.com') | |
.type('input[name="q"]', 'TrumpKlon') | |
.click('#search_button_homepage') | |
.evaluate(() => document.getElementsByTagName('title')[0].innerText) | |
.end() | |
.then((title) => { | |
console.log('Title:', title); | |
assert.equal(title, 'TrumpKlon at DuckDuckGo'); | |
}).then(() => done()); | |
}); | |
it('should show correct results', function (done) { | |
nightmare.goto('https://duckduckgo.com') | |
.type('input[name="q"]', 'TrumpKlon') | |
.click('#search_button_homepage') | |
.evaluate(() => document.getElementsByClassName('result__title')[0].innerText) | |
.end() | |
.then((text) => { | |
console.log('Result:', text); | |
assert.include(text, 'TrumpKlon'); | |
}).then(() => done()); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment