# @wdio/sync

> A WebdriverIO plugin. Helper module to run WebdriverIO commands synchronously

Latest version **7.27.0** (published 2022-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wdio/sync
pnpm add @wdio/sync
yarn add @wdio/sync
bun add @wdio/sync
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 7.27.0 |
| Published | 2022-11-23 |
| First published | 2018-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.0.0 <16 |
| Dependencies | 6 |
| Unpacked size | 28.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9834 |
| Author | Christian Bromann |
| Maintainers | christian-bromann, wdio-user, wswebcreation-nl |
| Keywords | webdriverio, wdio, fibers, sync, wdio-plugin |

## Links

- npm: https://www.npmjs.com/package/@wdio/sync
- Repository: https://github.com/webdriverio/webdriverio
- Homepage: https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-sync
- Issues: https://github.com/webdriverio/webdriverio/issues
- npm.io page: https://npm.io/package/@wdio/sync

## Dependencies (6)

- [fibers](https://npm.io/package/fibers.md) 5.0.3
- [@wdio/types](https://npm.io/package/@wdio/types.md) 7.26.0
- [webdriverio](https://npm.io/package/webdriverio.md) 7.27.0
- [@wdio/logger](https://npm.io/package/@wdio/logger.md) 7.26.0
- [@types/fibers](https://npm.io/package/@types/fibers.md) ^3.1.0
- [@types/puppeteer](https://npm.io/package/@types/puppeteer.md) ^5.4.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 7.27.0 (latest) — 2022-11-23
- 7.40.0 (v7) — 2024-12-18
- 7.0.0-beta.4 (beta) — 2021-02-09
- 5.23.0 (latest-5) — 2020-05-25
- 6.0.0-beta.1 (next) — 2020-03-18
- 7.36.0 — 2024-03-07
- 7.35.0 — 2024-02-13
- 7.34.0 — 2023-12-21
- 7.33.0 — 2023-10-06
- 7.32.4 — 2023-08-21
- 7.32.3 — 2023-07-24
- 7.32.2 — 2023-07-21
- 7.32.1 — 2023-07-11
- 7.32.0 — 2023-06-22
- 7.31.1 — 2023-04-17
- … 244 more at https://npm.io/package/@wdio/sync/versions

## README

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:

```js
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:

```js
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:

```js
// 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:

```js
// 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:

```js
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/']
    })
})
```

---
_Source: https://npm.io/package/@wdio/sync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
