Skip to content

Instantly share code, notes, and snippets.

@jochakovsky
Last active October 21, 2017 07:01
Show Gist options
  • Save jochakovsky/65cea6612f210705d470224a4da2a718 to your computer and use it in GitHub Desktop.
Save jochakovsky/65cea6612f210705d470224a4da2a718 to your computer and use it in GitHub Desktop.
WebdriverIO browser.waitUntil proposal
var assert = require('assert');
const RESOLVE_TIME = 50;
const TIMEOUT = 200;
describe('webdriver.io page', function() {
it('waitUntil should stop waiting when promise resolves truthy', function () {
const start = Date.now();
browser.waitUntil(new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, RESOLVE_TIME);
}), TIMEOUT);
const end = Date.now();
assert(end - start >= RESOLVE_TIME && end - start < TIMEOUT);
});
it('waitUntil should stop waiting when promise resolves falsey', function () {
const start = Date.now();
browser.waitUntil(new Promise((resolve) => {
setTimeout(() => {
resolve(false);
}, RESOLVE_TIME);
}), TIMEOUT);
const end = Date.now();
assert(end - start >= RESOLVE_TIME && end - start < TIMEOUT);
});
it('waitUntil should stop waiting when promise rejects truthy', function () {
const start = Date.now();
browser.waitUntil(new Promise((resolve, reject) => {
setTimeout(() => {
reject(true);
}, RESOLVE_TIME);
}), TIMEOUT);
const end = Date.now();
assert(end - start >= RESOLVE_TIME && end - start < TIMEOUT);
});
it('waitUntil should stop waiting when promise rejects falsey', function () {
const start = Date.now();
browser.waitUntil(new Promise((resolve, reject) => {
setTimeout(() => {
reject(false);
}, RESOLVE_TIME);
}), TIMEOUT);
const end = Date.now();
assert(end - start >= RESOLVE_TIME && end - start < TIMEOUT);
});
});
@jochakovsky
Copy link
Author

Current results:

․FFF

1 passing (27.90s)
3 failing

1) webdriver.io page waitUntil should stop waiting when promise resolves falsey:
Promise was rejected with the following reason: timeout
running firefox
Error: Promise was rejected with the following reason: timeout
    at waitUntil([object Promise], 8000) - index.js:316:3

2) webdriver.io page waitUntil should stop waiting when promise rejects truthy:
Promise was rejected with the following reason: undefined
running firefox
Error: Promise was rejected with the following reason: undefined
    at waitUntil([object Promise], 8000) - index.js:316:3

3) webdriver.io page waitUntil should stop waiting when promise rejects falsey:
Promise was rejected with the following reason: timeout
running firefox
Error: Promise was rejected with the following reason: timeout
    at waitUntil([object Promise], 8000) - index.js:316:3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment