Skip to content

Instantly share code, notes, and snippets.

@chodorowicz
Last active November 4, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chodorowicz/9c0dc4cc930897dbcc850b0ada12c41c to your computer and use it in GitHub Desktop.
Save chodorowicz/9c0dc4cc930897dbcc850b0ada12c41c to your computer and use it in GitHub Desktop.
webdriver
// count elements
// http://webdriver.io/api/protocol/elements.html
browser.elements('.OrdersList .Row')
.then(elements => {
assert.equal(elements.value.length, 999);
})
const elementWithText = 'h2=Create a new Order Sheet';
const cssSelector = '.ProductsBig span';
remote
// http://webdriver.io/api/utility/waitForExist.html
// exists
.waitForExist('.selector', 500)
// doesn't exist
.waitForExist('.selector', 500, true)
const webdriverio = require('webdriverio');
const chai = require('chai');
const expect = chai.expect;
const options = { desiredCapabilities: { browserName: 'chrome' } };
const remote = webdriverio.remote(options);
const testingUrl = 'http://google.com/';
const waitShort = 5000;
describe('Google', function() {
/** setting timeout for help describe block → this won't work with arrow functions */
this.timeout(40000);
beforeEach(() => {
/** return remote - it's a promise */
return remote.init();
});
it('should display page with title', function() {
/** either return promise or use done callback, in Mocha 3.* doing both fails test */
return remote
.url(testingUrl)
.getTitle().then((title) => {
expect(title).to.equal('Google');
})
.click('[href="http://google.com/some-link"]')
.waitUntil(() => remote.isVisible('.some-div'), waitShort)
});
afterEach(() => remote.end());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment