Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wdio/sync

Package Overview
Dependencies
Maintainers
3
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wdio/sync

A WebdriverIO plugin. Helper module to run WebdriverIO commands synchronously

  • 7.27.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-42.22%
Maintainers
3
Weekly downloads
 
Created
Source

WebdriverIO Sync

A WebdriverIO plugin. Helper module to run WebdriverIO commands synchronously

A WebdriverIO plugin. Helper module to run WebdriverIO commands synchronously. It overwrites global functions depending on the test framework (e.g. for Mocha describe and it) and uses Fibers to make commands of WebdriverIO using the wdio testrunner synchronous. This package is consumed by all wdio framework adapters.

Usage

Using WDIO Testrunner

If you are using the WDIO testrunner all you need to make all your specs run synchronous is to have @wdio/sync installed in your project. The testrunner automatically will detect it and transform the commands to make a test like this:

describe('webdriver.io page', () => {
    it('should have the right title', async () => {
        await browser.url('https://webdriver.io')
        await expect(browser)
            .toHaveTitle('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO')
    })
})

easier to read and write like this:

describe('webdriver.io page', () => {
    it('should have the right title', () => {
        browser.url('https://webdriver.io')
        expect(browser).toHaveTitle('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO')
    })
})

Using WebdriverIO as standalone package

Given you have a simple standalone WebdriverIO script like this:

// standalone.js
const { remote } = require('webdriverio')
const sync = require('@wdio/sync').default

;(() => {
    const browser = await remote({
        outputDir: __dirname,
        capabilities: {
            browserName: 'chrome'
        }
    })

    await browser.url('https://webdriver.io')
    console.log(await browser.getTitle())
    await browser.deleteSession()
})().catch(console.error)

With this package you can make WebdriverIO commands synchronous by using the sync wrapper:

// standalone.js
const { remote } = require('webdriverio')
const sync = require('@wdio/sync').default

remote({
    runner: 'local',
    outputDir: __dirname,
    capabilities: {
        browserName: 'chrome'
    }
}).then((browser) => sync(() => {
    /**
     * sync code from here on
     */
    browser.url('https://webdriver.io')
    console.log(browser.getTitle())
    browser.deleteSession()
}))

Switching Between Sync And Async

While using @wdio/sync you can still switch between both by using the browser.call() command. It allows you to run async code and return the result into a synchronous environment. For example:

describe('webdriver.io page', () => {
    it('should have the right title', () => {
        /**
         * synchronous execution here
         */
        browser.url('https://webdriver.io')

        const result = browser.call(async () => {
            /**
             * asynchronous execution here
             */
            await browser.url('https://google.com')
            return Promise.all([
                browser.getTitle(),
                browser.getUrl()
            ])
        })

        /**
         * synchronous execution here
         */
        console.log(result) // returns: ['Google', 'https://www.google.com/']
    })
})

Keywords

FAQs

Package last updated on 23 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc