testplane icon indicating copy to clipboard operation
testplane copied to clipboard

waitUntil function from webdriver.io not usable

Open utrotzek opened this issue 6 years ago • 2 comments
trafficstars

Currently it is not possible to implement some complex checks using the waitUntil function of webdriver.io. This is because of two reasons:

  1. No access to the browser object within the function waitUntil. I tried this.browser.$('#myElement') and this.$('#myElement') but i cannot select anyelement of the page. I'll get the following JSON object when logging it with console.log
{ defer:
   defer {
     promise:
      Promise {
        promiseDispatch: [Function],
        valueOf: [Function],
        inspect: [Function] },
     resolve: [Function],
     fulfill: [Function],
     reject: [Function],
     notify: [Function] },
  promise:
   Promise {
     promiseDispatch: [Function],
     valueOf: [Function],
     inspect: [Function] },
  lastPromise:
   Promise {
     promiseDispatch: [Function],
     valueOf: [Function],
     inspect: [Function] },
  desiredCapabilities:
   { javascriptEnabled: true,
     locationContextEnabled: true,
     handlesAlerts: true,
     rotatable: true,
     browserName: 'chrome',
     chromeOptions: { w3c: false },
     loggingPrefs: { browser: 'ALL', driver: 'ALL' } },
  requestHandler:
   RequestHandler {
     sessionID: '688b40439a82c317db0038b597aea131',
     startPath: '/wd/hub',
     gridApiStartPath: '/grid/api',
     eventHandler:
      EventEmitter {
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined },
     logger: Logger { logLevel: 'error' },
     defaultOptions:
      { port: '4444',
        waitforTimeout: 1000,
        waitforInterval: 500,
        coloredLogs: true,
        deprecationWarnings: true,
        logLevel: 'error',
        baseUrl: 'https://local.stadt-muenster.citeq.de',
        onError: [],
        connectionRetryTimeout: 90000,
        connectionRetryCount: 0,
        path: '/wd/hub',
        desiredCapabilities: [Object],
        screenshotPath: null,
        hostname: 'selenium-hub',
        protocol: 'http' } },
  logger: Logger { logLevel: 'error' },
  options:
   { port: '4444',
     waitforTimeout: 1000,
     waitforInterval: 500,
     coloredLogs: true,
     deprecationWarnings: true,
     logLevel: 'error',
     baseUrl: 'https://local.stadt-muenster.citeq.de',
     onError: [],
     connectionRetryTimeout: 90000,
     connectionRetryCount: 0,
     path: '/wd/hub',
     desiredCapabilities: { browserName: 'chrome', chromeOptions: [Object] },
     screenshotPath: null,
     hostname: 'selenium-hub',
     protocol: 'http' },
  commandList:
   [ { name: 'windowHandleSize',
       args: [Array],
       timestamp: 1568488827958,
       stack:
        'windowHandleSize([object Object]) (/home/node/app/node_modules/hermione/lib/browser/existing-browser.js:100:33)',
       result: [Object] },
     { name: 'scroll',
       args: [Array],
       timestamp: 1568488828661,
       stack:
        'scroll("body", 0, 0) (/home/node/app/node_modules/hermione/lib/worker/runner/test-runner/index.js:86:39)' },
     { name: 'element',
       args: [Array],
       timestamp: 1568488828662,
       stack:
        'element("body") (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/scroll.js:94:21)',
       result: [Object] },
     { name: 'elementIdLocation',
       args: [Array],
       timestamp: 1568488828685,
       stack:
        'elementIdLocation("0.5985023519061072-1") (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/scroll.js:102:26)',
       result: [Object] },
     { name: 'execute',
       args: [Array],
       timestamp: 1568488828697,
       stack:
        'execute(<Function>, 8, 8) (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/scroll.js:104:26)',
       result: [Object] },
     { name: 'moveToObject',
       args: [Array],
       timestamp: 1568488828709,
       stack:
        'moveToObject("body", 0, 0) (/home/node/app/node_modules/hermione/lib/worker/runner/test-runner/index.js:87:33)' },
     { name: 'element',
       args: [Array],
       timestamp: 1568488828709,
       stack:
        'element("body") (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/moveToObject.js:47:17)',
       result: [Object] },
     { name: 'moveTo',
       args: [Array],
       timestamp: 1568488828723,
       stack:
        'moveTo("0.5985023519061072-1", 0, 0) (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/moveToObject.js:55:22)',
       result: [Object] },
     { name: 'url',
       args: [Array],
       timestamp: 1568488828745,
       stack:
        'url("/fixtures/content-elemente/text-mit-bild.html") (/home/node/app/tests/desktop/plugins/imageSlider.js:5:14)' },
     { name: 'url',
       args: [Array],
       timestamp: 1568488828747,
       stack:
        'url("https://local.stadt-muenster.citeq.de/fixtures/content-elemente/text-mit-bild.html") (/home/node/app/node_modules/hermione/lib/browser/existing-browser.js:57:20)',
       result: [Object] },
     { name: 'execute',
       args: [Array],
       timestamp: 1568488831312,
       stack:
        'execute("return typeof __geminiCore !== "undefined"? __geminiCore.resetZoom() : {error: "ERRNOFUNC"}") (/home/node/app/node_modules/hermione/lib/browser/existing-browser.js:163:30)',
       result: [Object] },
     { name: 'execute',
       args: [Array],
       timestamp: 1568488831327,
       stack:
        'execute("(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&...) (/home/node/app/node_modules/hermione/lib/browser/existing-browser.js:167:30)',
       result: [Object] },
     { name: 'execute',
       args: [Array],
       timestamp: 1568488831358,
       stack:
        'execute("return typeof __geminiCore !== "undefined"? __geminiCore.resetZoom() : {error: "ERRNOFUNC"}") (/home/node/app/node_modules/hermione/lib/browser/existing-browser.js:163:30)',
       result: [Object] },
     { name: 'assertView',
       args: [Array],
       timestamp: 1568488831367,
       stack:
        'assertView("image-slider-default-image", "header") (/home/node/app/tests/desktop/plugins/imageSlider.js:6:14)' },
     { name: 'execute',
       args: [Array],
       timestamp: 1568488831368,
       stack:
        'execute("return typeof __geminiCore !== "undefined"? __geminiCore.prepareScreenshot(["header"], {"ignoreSele...) (/home/node/app/node_modules/hermione/lib/browser/existing-browser.js:163:30)',
       result: [Object] },
     { name: 'screenshot',
       args: [],
       timestamp: 1568488831380,
       stack:
        'screenshot() (/home/node/app/node_modules/hermione/lib/browser/existing-browser.js:30:30)',
       result: [Image] },
     { name: 'click',
       args: [Array],
       timestamp: 1568488832165,
       stack:
        'click(".bx-next") (/home/node/app/tests/desktop/plugins/imageSlider.js:7:14)' },
     { name: 'element',
       args: [Array],
       timestamp: 1568488832166,
       stack:
        'element(".bx-next") (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/click.js:12:17)',
       result: [Object] },
     { name: 'elementIdClick',
       args: [Array],
       timestamp: 1568488832184,
       stack:
        'elementIdClick("0.5504585026512787-1") (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/click.js:20:22)',
       result: [Object] },
     { name: 'isVisible',
       args: [Array],
       timestamp: 1568488832244,
       stack:
        'isVisible(".bxslider li:first-child img") (/home/node/app/tests/desktop/plugins/imageSlider.js:8:14)' },
     { name: 'elements',
       args: [Array],
       timestamp: 1568488832244,
       stack:
        'elements(".bxslider li:first-child img") (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/isVisible.js:54:17)',
       result: [Object] },
     { name: 'elementIdDisplayed',
       args: [Array],
       timestamp: 1568488832263,
       stack:
        'elementIdDisplayed("0.5504585026512787-2") (/home/node/app/node_modules/@gemini-testing/webdriverio/build/lib/commands/isVisible.js:71:55)',
       result: true },
     { name: 'waitUntil',
       args: [Array],
       timestamp: 1568488832323,
       stack:
        'waitUntil(<Function>, 5000, "expected text to be different after 5s") (/home/node/app/tests/desktop/plugins/imageSlider.js:12:14)' } ],
  isMobile: false,
  isIOS: false,
  isAndroid: false,
  next: [Function],
  finally: [Function],
  call: [Function],
  then: [Function],
  catch: [Function],
  inspect: [Function],
  unify: [Function],
  addCommand: [Function],
  getPrototype: [Function],
  transferPromiseness: [Function],
  stack:
   'getText("#inhalts-spalte") (/home/node/app/tests/desktop/plugins/imageSlider.js:13:34)',
  depth: 1,
  name: 'getText',
  lastResult: undefined }
  1. Error message Error: Promise was rejected with the following reason: undefined when using waitUntil
.waitUntil(function () {
            return this.getText('#myElement') === 'I am now different'
}, 5000, 'expected text to be different after 5s');

The above mentioned code is describe in the webdriver documentation here: http://v4.webdriver.io/api/utility/waitUntil.html

Am I doing something wrong

utrotzek avatar Sep 17 '19 14:09 utrotzek

Hi. In hermione webdriverio used in Standalone mode In this mode getText is asynchronous method, so you should wait the result before using it.

.waitUntil(async function () {
    const text = await this.getText('#myElement');
    return  text === 'I am now different'
}, 5000, 'expected text to be different after 5s');

j0tunn avatar Sep 17 '19 15:09 j0tunn

Nice, that worked! :+1: Thanks a lot.

I think it would be nice to find that (and some more examples) in the documentation. When I'm done with my project I could provide a PR for that.

utrotzek avatar Sep 18 '19 06:09 utrotzek