What is @wdio/protocols?
@wdio/protocols is a package that provides WebDriver and Appium protocol bindings for the WebdriverIO framework. It allows you to interact with browser and mobile automation protocols, enabling you to perform a wide range of automation tasks.
What are @wdio/protocols's main functionalities?
WebDriver Protocol
This feature allows you to interact with the WebDriver protocol to automate browser actions. The code sample demonstrates how to initialize a WebDriver session, navigate to a URL, get the page title, and then close the session.
const { WebDriverProtocol } = require('@wdio/protocols');
const session = new WebDriverProtocol({
hostname: 'localhost',
port: 4444,
path: '/wd/hub'
});
session.init({
capabilities: {
browserName: 'chrome'
}
}).then(() => {
return session.url('https://example.com');
}).then(() => {
return session.getTitle();
}).then(title => {
console.log('Page title is:', title);
return session.deleteSession();
}).catch(err => {
console.error('Error:', err);
});
Appium Protocol
This feature allows you to interact with the Appium protocol to automate mobile app actions. The code sample demonstrates how to initialize an Appium session, navigate to a URL within the app, get the app title, and then close the session.
const { AppiumProtocol } = require('@wdio/protocols');
const session = new AppiumProtocol({
hostname: 'localhost',
port: 4723,
path: '/wd/hub'
});
session.init({
capabilities: {
platformName: 'Android',
deviceName: 'emulator-5554',
app: '/path/to/app.apk'
}
}).then(() => {
return session.url('https://example.com');
}).then(() => {
return session.getTitle();
}).then(title => {
console.log('App title is:', title);
return session.deleteSession();
}).catch(err => {
console.error('Error:', err);
});
Other packages similar to @wdio/protocols
selenium-webdriver
selenium-webdriver is a popular package for browser automation using the WebDriver protocol. It provides a high-level API for controlling web browsers. Compared to @wdio/protocols, selenium-webdriver is more widely used and has a larger community, but it does not support Appium protocol out of the box.
appium
appium is a package that provides bindings for the Appium protocol, allowing you to automate mobile applications. It is similar to @wdio/protocols in terms of mobile automation capabilities but does not include WebDriver protocol bindings.
WebdriverIO Protocol Helper
This package stores the definition for various automation protocols such as WebDriver or vendor specific protocol extensions like for SauceLabs. Unless you are interested in generating a WebDriver client there should be no reason why you should need this package. This package holds the definition of the following protocols:
Install
To install the package, run:
$ npm install @wdio/protocols
Usage
You can get data by importing the package as follows:
import { WebDriverProtocol, MJsonWProtocol, JsonWProtocol, AppiumProtocol, ChromiumProtocol, SauceLabsProtocol, SeleniumProtocol } from '@wdio/protocols'
console.log(WebDriverProtocol['/session'].POST.description)
For more information on WebdriverIO see the homepage.