From 1b055af545bd8f3320d8b6e8eda5f8e4511fd553 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <cwillisf@media.mit.edu> Date: Tue, 7 May 2019 16:28:34 -0700 Subject: [PATCH] add timeouts & messages to all driver.wait calls --- test/helpers/selenium-helper.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/helpers/selenium-helper.js b/test/helpers/selenium-helper.js index 99320f577..4b0d54408 100644 --- a/test/helpers/selenium-helper.js +++ b/test/helpers/selenium-helper.js @@ -8,6 +8,11 @@ const {By, until, Button} = webdriver; const USE_HEADLESS = process.env.USE_HEADLESS !== 'no'; +// The main reason for this timeout is so that we can control the timeout message and report details; +// if we hit the Jasmine default timeout then we get a terse message that we can't control. +// The Jasmine default timeout is 30 seconds so make sure this is lower. +const DEFAULT_TIMEOUT_MILLISECONDS = 20 * 1000; + class SeleniumHelper { constructor () { bindAll(this, [ @@ -26,8 +31,11 @@ class SeleniumHelper { ]); } - elementIsVisible (element) { - return this.driver.wait(until.elementIsVisible(element)); + elementIsVisible (element, { + message = 'elementIsVisible timed out', + timeout = DEFAULT_TIMEOUT_MILLISECONDS + } = {}) { + return this.driver.wait(until.elementIsVisible(element), timeout, message); } get scope () { @@ -79,8 +87,11 @@ class SeleniumHelper { return this.driver; } - findByXpath (xpath) { - return this.driver.wait(until.elementLocated(By.xpath(xpath), 5 * 1000)); + findByXpath (xpath, { + message = `findByXpath timed out for path: ${xpath}`, + timeout = DEFAULT_TIMEOUT_MILLISECONDS + } = {}) { + return this.driver.wait(until.elementLocated(By.xpath(xpath)), timeout, message); } findByText (text, scope) { @@ -120,8 +131,11 @@ class SeleniumHelper { return this.clickXpath(`//button//*[contains(text(), '${text}')]`); } - waitUntilGone (element) { - return this.driver.wait(until.stalenessOf(element)); + waitUntilGone (element, { + message = 'waitUntilGone timed out', + timeout = DEFAULT_TIMEOUT_MILLISECONDS + } = {}) { + return this.driver.wait(until.stalenessOf(element), timeout, message); } getLogs (whitelist) { -- GitLab