What is @wdio/globals?
@wdio/globals is a package that provides global variables and functions for WebdriverIO, a popular automation test framework. It simplifies the setup and usage of WebdriverIO by offering a set of globally accessible utilities.
What are @wdio/globals's main functionalities?
Global Browser Object
The global `browser` object allows you to interact with the browser instance directly. This includes navigating to URLs, interacting with elements, and more.
browser.url('https://example.com');
Global Expect Function
The global `expect` function is used for assertions in your tests. It allows you to make assertions about the state of the browser or elements within it.
expect(browser).toHaveTitle('Example Domain');
Global $ and $$ Functions
The global `$` and `$$` functions are shorthand for selecting single and multiple elements, respectively. They simplify the process of element selection in your tests.
const element = $('selector'); const elements = $$('selector');
Other packages similar to @wdio/globals
selenium-webdriver
Selenium WebDriver is a widely-used tool for browser automation. It provides a more low-level API compared to WebdriverIO, requiring more boilerplate code to achieve similar tasks.
cypress
Cypress is an end-to-end testing framework that offers a more developer-friendly experience with automatic waiting and a more intuitive API. However, it is limited to testing within the browser and does not support multiple browser instances.
nightwatch
Nightwatch.js is an end-to-end testing framework built on top of Selenium WebDriver. It provides a higher-level API compared to Selenium WebDriver but is not as feature-rich or user-friendly as WebdriverIO.
WDIO Globals
A helper utility for importing global variables directly
This package can be used to import global variables explicitly, e.g.
import { browser, $, $$, expect } from '@wdio/globals'
describe('my test', () => {
it('can do something', async () => {
})
})
For more information on WebdriverIO Globals, check out the docs.