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.

Incorrect doc: WebdriverIO Sync

See original GitHub issue

Pre-check

Describe the improvement

I’d like to report

  • Unclear documentation
  • A typo
  • Missing documentation
  • Other

Description of the improvement / report I am trying to test an async helper method I have created in sync mode to make sure users of the helper can use it in both sync and async mode using the following doc Using WebdriverIO as standalone package and noticed the following issues:

  • .then((browser) =>
    • Typescript error: TS2339: Property 'then' does not exist on type 'BrowserObject'
    • Looking at node_modules/webdriverio/webdriverio.d.ts I see remote() returns a BrowserObject not a promise
    • If I suppress the error (assuming possible incorrect typedef) and run the test using wdio cli the then block does not run.
      • e.g. }).then((browser) => sync(() => { expect(true).toBe(false); }) still passes
  • Can you please add/improve doc to describe how to use a async helper method that uses browser object to work in sync mode. How can I design helper method or browser command that works in both sync and async mode?
    • If I try using my async helper method (e.g.checkIssues()) within the sync() block (without creating a remote, I get a UnhandledPromiseRejectionWarning: Unhandled promise rejection.
         sync(() => {
           browser.url(htmlFileWithIssues);
           expect(() => checkIssues()).toThrow();
          });
      
    • using browser.call() to wrap the async method as described in the doc doesn’t help
       it('should work with sync mode', () => { 
         const sync = require('@wdio/sync').default;
         sync(() => {
             browser.url(htmlFileWithIssues);
             browser.call(async () => {
                 expect(await checkIssues()).toThrow();
             });
         });
      
  • runner: true,
  • Switching Between Sync And Async has a typo: you can still switch between both boths by using the (Fixed in https://github.com/webdriverio/webdriverio/pull/5598)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
christian-bromanncommented, Jul 10, 2020

That is indeed a bug.

Fixed in #5599

0reactions
christian-bromanncommented, Jul 14, 2020

How can I similarly make my async helper work seamlessly in both sync and async modes without the user having to know/care about it?

You can just check if @wdio/sync is installed or not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration File - WebdriverIO
The configuration file contains all necessary information to run your test suite. It's a NodeJS module that exports a JSON.
Read more >
Investigate if WebdriverIO `sync: false` would be useful to us ...
With version 4, it is supposed to be synchronous by default. Setting sync: false being for people still having async tests so they...
Read more >
webdriverio/webdriverio - Gitter
Is there a problem there? Radim Daniel Pánek. @rdpanek. Hello, i try documentation for v6 and this page doesn't exist https://webdriver.io/docs/sync-vs- ...
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?
Read more >
BrowserStack, WDIO, Cucumber, TypeScript - Stack Overflow
It's a pretty late answer, but it looks like the problem is with the types ... Please avoid importing webdriverio or @wdio/sync explicitly....
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