From 4f89f06420c8ca912867d8a72b21aaf04aa4ebc7 Mon Sep 17 00:00:00 2001 From: Aaron D Borden Date: Wed, 12 Apr 2017 15:41:30 -0700 Subject: [PATCH] Allow BaseElement to accept selector or WebElement Sometimes selectors are hard to write (because webdriver does not support all selectors), so you want to traverse to the target element using WebElements. Selectors are convenient, so accept both and give a helpful error message. --- .../test/functional/pageobjects/base.element.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/static_src/test/functional/pageobjects/base.element.js b/static_src/test/functional/pageobjects/base.element.js index be8ee2fb..4f9f0766 100644 --- a/static_src/test/functional/pageobjects/base.element.js +++ b/static_src/test/functional/pageobjects/base.element.js @@ -10,9 +10,18 @@ * to deal with a single component. **/ +import assert from 'assert'; + export default class BaseElement { - constructor(browser, webElement) { + constructor(browser, webElementOrSelector) { this.browser = browser; + + let webElement = webElementOrSelector; + if (typeof webElementOrSelector === 'string') { + webElement = browser.element(webElementOrSelector); + } + + assert(webElement.value, `Element '${webElement.selector}' does not exist in the DOM.`); this.webElementId = webElement.value.ELEMENT; }