question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using async/await breaks @wdio/sync with e.g. browser.$(...).waitForExist is not a function

See original GitHub issue

Environment:

  • WebdriverIO version: 6.3.6
  • Mode: Standalone
  • Node.js version: v12.15.0
  • NPM version: 6.14.7
  • Browser name and version: Chrome 84.0.4147.105
  • Platform name and version: macOS Catalina 10.15
  • Additional wdio packages used (if applicable): @wdio/sync

Config of WebdriverIO No configuration

Describe the bug Using @wdio/sync package to execute statements synchronously breaks when used in combination with async/await before/after the call to sync. A typical result is that the browser object inside the sync call has not been set up to be synchronous:

TypeError: browser.$(...).waitForExist is not a function

To Reproduce See a minimal code example below:

index.js
const remote = require("webdriverio").remote;
const sync = require("@wdio/sync").default;

let browser;
(async () => {
  browser = await remote({
    capabilities: { browserName: "chrome" },
  });

  await browser.navigateTo("https://webdriver.io");

  await sync(() => {
    browser.$("#search_input_react").waitForExist();
  });

  await browser.deleteSession();
})().catch((err) => {
  console.error(err);
  return browser.deleteSession();
});
package.json
{
  "name": "wdio-bug",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@wdio/sync": "^6.3.6",
    "webdriverio": "^6.3.6"
  }
}

Expected behavior I expect one to be able to use @wdio/sync package and the sync function to execute statements synchronously in combination with using async/await constructs next to each other.

Given the minimal example above, I would argue that whether browser.navigateTo("https://webdriver.io"); is inside the sync call or not (as long as we make sure to wait for the result) should yield the same result.

Log

console output
2020-08-04T08:48:03.630Z INFO webdriverio: Initiate new session using the devtools protocol
2020-08-04T08:48:03.635Z INFO devtools: Launch Google Chrome with flags: --disable-extensions --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-sync --metrics-recording-only --disable-default-apps --mute-audio --no-first-run --disable-hang-monitor --disable-prompt-on-repost --disable-client-side-phishing-detection --password-store=basic --use-mock-keychain --disable-component-extensions-with-background-pages --disable-breakpad --disable-dev-shm-usage --disable-ipc-flooding-protection --disable-renderer-backgrounding --enable-features=NetworkService,NetworkServiceInProcess --disable-features=site-per-process,TranslateUI,BlinkGenPropertyTrees --window-position=0,0 --window-size=1200,900
2020-08-04T08:48:04.686Z INFO devtools: Connect Puppeteer with browser on port 60187
2020-08-04T08:48:05.567Z INFO devtools: COMMAND navigateTo("https://webdriver.io")
2020-08-04T08:48:08.155Z INFO devtools: RESULT null
2020-08-04T08:48:08.170Z INFO devtools: COMMAND findElement("css selector", "#search_input_react")
2020-08-04T08:48:08.189Z INFO devtools: RESULT { 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' }
TypeError: browser.$(...).waitForExist is not a function
    at ***/index.js:13:38
2020-08-04T08:48:08.206Z INFO devtools: COMMAND deleteSession()
2020-08-04T08:48:08.207Z INFO devtools: RESULT null

Additional context One may argue that the problem is easily circumvented by simply issuing all wdio calls inside the sync function, avoiding the need for using async/await all together. In this trivial example, yes, but in general code may not be related as closely as this example illustrates (i.e. it may be split in different functions/classes/files etc.).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
joshskumarcommented, Aug 24, 2020

hi,

the code works when used as below

const remote = require("webdriverio").remote;
const sync = require("@wdio/sync").default;

let browser;
(async () => {
  browser = await remote({
    capabilities: { browserName: "chrome" },
  });

  await browser.navigateTo("https://webdriver.io");

  await sync( async () => {
    (await browser.$("#search_input_react")).waitForExist({
        timeout:5
    });
  });
  await browser.deleteSession();
})().catch((err) => {
  console.error(err);
  return browser.deleteSession();
});

so looks like the waitForExist is not working when there is no await for the element find…

this will be like this because the without the Object created it will not be able to find the function waitForExist()

0reactions
christian-bromanncommented, Jul 27, 2021

As we are moving away from sync execution, this issue is not relevant anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using async/await breaks @wdio/sync with e.g. browser ...
Using async/await breaks @wdio/sync with e.g. browser.$(...).waitForExist is not a function · WebdriverIO version: 6.3.6 · Mode: Standalone · Node.
Read more >
webdriverio/webdriverio - Gitter
I am using WDIO v5 with Mocha, I want to use 'bail' configuration. Can someone help me with this, like if before hook...
Read more >
Webdriverio using async/await - What is recommended? [closed]
I am running my functional tests using WebdriverIO. I can get the WebdriverIO tests to pass even without async/await .
Read more >
WebdriverIO Sync mode update | WebdriverIO v7 to v8 changes
webdriverio #automationbroIs WebdriverIO getting rid of the Sync mode? How to use WebdriverIO in Async mode? In this video, we will be ...
Read more >
WebdriverIO Important Sync mode Updates - - Automation Bro
However, there are few downsides to using async/await – ... WebdriverIO came up with sync mode and created a @wdio/sync plugin which allows ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found