Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
webdriverio
Advanced tools
WebdriverIO is an open-source testing utility for Node.js that allows you to control a browser or a mobile application with just a few lines of code. It is built on top of WebDriver protocol and supports both desktop browsers and mobile applications. It provides a lot of useful features to create end-to-end tests, supports synchronous and asynchronous modes, and integrates with various test frameworks like Mocha, Jasmine, and Cucumber.
Browser Automation
Automate web browsers by performing actions like navigating to URLs, clicking on elements, and retrieving page information.
const { remote } = require('webdriverio');
(async () => {
const browser = await remote({
capabilities: { browserName: 'chrome' }
});
await browser.url('https://example.com');
const title = await browser.getTitle();
console.log('Title was: ' + title);
await browser.deleteSession();
})();
Element Interaction
Interact with web elements such as input fields, buttons, and links by sending keystrokes, clicking, and retrieving attributes.
const { remote } = require('webdriverio');
(async () => {
const browser = await remote({
capabilities: { browserName: 'chrome' }
});
await browser.url('https://example.com/login');
await browser.setValue('#username', 'user123');
await browser.setValue('#password', 'pass123');
await browser.click('#submit');
await browser.deleteSession();
})();
Mobile Application Testing
Test mobile applications by launching them on simulators, emulators, or real devices and interacting with them just like with browser automation.
const { remote } = require('webdriverio');
(async () => {
const browser = await remote({
path: '/wd/hub',
capabilities: {
platformName: 'Android',
'appium:deviceName': 'emulator',
'appium:app': '/path/to/your.app'
}
});
// Your mobile testing code here
await browser.deleteSession();
})();
Integration with Test Runners
Easily integrate with test runners like Mocha, Jasmine, or Cucumber to create structured and maintainable test suites.
const { remote } = require('webdriverio');
describe('My application', () => {
it('should work with webdriverio', async () => {
const browser = await remote({
capabilities: { browserName: 'chrome' }
});
await browser.url('https://example.com');
expect(await browser.getTitle()).toBe('Expected Title');
await browser.deleteSession();
});
});
Selenium WebDriver is one of the most popular browser automation tools. It requires setting up a standalone server and writing more boilerplate code compared to WebdriverIO, which provides a more concise API and integrated test runner support.
Puppeteer is a Node library developed by the Chrome DevTools team. It provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer is typically faster and more stable for Chrome/Chromium automation because it uses the DevTools protocol, but it does not support multiple browsers out of the box like WebdriverIO does.
Cypress is a front-end testing tool built for the modern web. It is both a library for writing tests as well as a test runner. It offers a rich interactive interface for running tests but is limited to running tests within its own browser-based test runner, which can be a limitation compared to WebdriverIO's support for various browsers and mobile platforms.
Nightwatch.js is an automated testing framework for web applications and websites, written in Node.js and using the W3C WebDriver API. It is similar to WebdriverIO but has its own test runner and asserts library, which can make it easier to set up and start writing tests. However, it might not be as feature-rich as WebdriverIO in terms of community plugins and integrations.
This library is a webdriver module for Node.js. It makes it possible to write super easy selenium tests in your favorite BDD or TDD test framework. It was originated by Camilo Tapia's inital selenium project called WebdriverJS.
Have a look at the many examples.
For news or announcements follow @webdriverio on Twitter.
npm install webdriverio
Make sure you have a running Selenium standalone/grid/hub.
Or use selenium-standalone package to run one easily.
var webdriverio = require('../index');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
webdriverio
.remote(options)
.init()
.url('http://www.google.com')
.title(function(err, res) {
console.log('Title was: ' + res.value);
})
.end();
See the full list of options you can pass to .remote(options)
.
Type: Object
Example:
browserName: 'chrome', // options: firefox, chrome, opera, safari
version: '27.0', // browser version
platform: 'XP', // OS platform
tags: ['tag1','tag2'], // specify some tags (e.g. if you use Sauce Labs)
name: 'my test' // set name for test (e.g. if you use Sauce Labs)
See the Selenium documentation for a list of the available capabilities
.
Type: String
Default: silent
Options: verbose | silent | command | data | result
Saves a screenshot to a given path if Selenium driver crashes
Type: String
|null
Default: null
Type: Boolean
Default: false
Set to true if you always want to reuse the same remote
The JsonWireProtocol provides several strategies to query an element. WebdriverIO simplifies these to make it more familiar with the common existing selector libraries like Sizzle. The following selector types are supported:
client.click('h2.subheading a', function(err,res) {...})
etc.<a href="http://webdriver.io">WebdriverIO</a>
)
query the text starting with an equal (=) sign. In this example use =WebdriverIO
*=
in front of the query string (e.g. *=driver
)<tag>
or <tag />
[name="some-name"]
as
selector parameter//BODY/DIV[6]/DIV[1]/SPAN[1]
In near future WebdriverIO will cover more selector features like form selector (e.g. :password
,:file
etc)
or positional selectors like :first
or :nth
.
WebdriverIO inherits several function from the NodeJS EventEmitter object. Additionally it provides an experimental way to register events on browser side (like click, focus, keypress etc.).
The following functions are supported: on
,once
,emit
,removeListener
,removeAllListeners
.
They behave exactly as described in the official NodeJS docs.
There are some predefined events (error
,init
,end
, command
) which cover important
WebdriverIO events.
Example:
client.on('error', function(e) {
// will be executed everytime an error occured
// e.g. when element couldn't be found
console.log(e.body.value.class); // -> "org.openqa.selenium.NoSuchElementException"
console.log(e.body.value.message); // -> "no such element ..."
})
All commands are chainable, so you can use them while chaining your commands
var cnt;
client
.init()
.once('countme', function(e) {
console.log(e.elements.length, 'elements were found');
})
.elements('.myElem', function(err,res) {
cnt = res.value;
})
.emit('countme', cnt)
.end();
Note: make sure you check out the Browserevent side project that enables event-handling on client side (Yes, in the browser!! ;-).
If you want to extend the client with your own set of commands there is a
method called addCommand
available from the client object:
var client = require("webdriverio").remote();
// example: create a command the returns the current url and title as one result
// last parameter has to be a callback function that needs to be called
// when the command has finished (otherwise the queue stops)
client.addCommand("getUrlAndTitle", function(customVar, cb) {
this.url(function(err,urlResult) {
this.getTitle(function(err,titleResult) {
var specialResult = {url: urlResult.value, title: titleResult};
cb(err,specialResult);
console.log(customVar); // "a custom variable"
})
});
});
client
.init()
.url('http://www.github.com')
.getUrlAndTitle('a custom variable', function(err,result){
assert.equal(null, err)
assert.strictEqual(result.url,'https://github.com/');
assert.strictEqual(result.title,'GitHub · Build software better, together.');
})
.end();
If you want to help us in developing WebdriverIO, you can easily add mocha tests and run them locally:
npm install -g selenium-standalone http-server phantomjs
# start a local Selenium instances
start-selenium
# serves the test directory holding the test files
http-server
# runs tests !
npm test
WebdriverIO supports
See the corresponding examples.
These are the current implemented command methods. All methods take from 0 to a couple of parameters. Also all methods accept a callback so that we can assert values or have more logic when the callback is called. WebdriverIO has all JSONWire protocol commands implemented and even a whole bunch of undocumented Appium commands of the Selenium.
String
selector, String|String[]
value, Function
callback)Left arrow
or Back space
. You'll find all supported characters here. To do that, the value has to correspond to a key from the table.String
selector, String
localFilePath, Function
callback)<input type=file>
, will upload the local file to the browser machine and fill the form accordingly. It does not submit the form for you.String
selector, Function
callback)String
selector, Function
callback)String
tab ID to focus on,] Function
callback)String
name, Function
callback)String
selector, Function
callback)String
selector, Number
startX, Number
startY, Number
endX, Number
endY, Number
touchCount, Number
duration, Function
callback)String
sourceCssSelector, String
destinationCssSelector, Function
callback)String
selector, Number
touchCount, Number
duration, Function
callback)String
selector, Number
touchCount, Number
duration, Function
callback)String
selector, Number
touchCount, Number
duration, Function
callback)String
selector, Number
touchCount, Number
duration, Function
callback)String
eventName, [arg1], [arg2], [...])Function
callback)Function
callback)String
or Function
script, Array
arguments, Function
callback)Function
, arguments is required.String
selector, Number
startX, Number
startY, Number
endX, Number
endY, Number
touchCount, Function
callback)String
selector, String
attribute name, Function
callback)String
name, Function
callback)String
selector, String
css property name, Function
callback)Function
callback)String
selector, Function
callback)String
selector, Function
callback)String
selector, Function
callback)Function
callback)Function
callback)Function
callback)String
selector, Function
callback)String
selector, Function
callback)Function
callback)String
selector, Function
callback)String
selector, Function
callback)String
selector, Function
callback)String
selector, Function
callback)String
selector,Function
callback)String
selector, Function
callback)String
selector, Function
callback)String
url, String
name for the new window, String
new window features (e.g. size, position, scrollbars, etc.), Function
callback)Window.open()
in a browserString
eventName, Function
fn)init
,command
,end
,error
)String
eventName, Function
fn)init
,command
,end
,error
)Integer
milliseconds, Function
callback)Function
callback)String
selector, Function
callback)String
eventName, Function
fn)String
eventName])String
selector, Function
callback)String
path to file, Function
callback)String
selector, Function
callback)scroll(xoffset,yoffset,callback)
).Object
cookie, Function
callback)String
orientation, Function
callback)String
selector, String|String[]
value, Function
callback)Left arrow
or Back space
. You'll find all supported characters here. To do that, the value has to correspond to a key from the table.String
selector, Function
callback)String
tab ID)String
selector,Number
x,Number
y,Number
tapCount,Number
touchCount,Number
duration,Function
callback)String
selector, Function
callback)String
selector, Integer
milliseconds, Function
callback)The npm module for this library is maintained by:
FAQs
Next-gen browser and mobile automation test framework for Node.js
The npm package webdriverio receives a total of 1,440,488 weekly downloads. As such, webdriverio popularity was classified as popular.
We found that webdriverio demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.