Welcome to FullStack. We use cookies to enable better features on our website. Cookies help us tailor content to your interests and locations and provide other benefits on the site. For more information, please see our Cookies Policy and Privacy Policy.
WebdriverIO is written entirely in JavaScript and installation is done through NPM commands. I was always thinking that web automation meant figuring out how to get some complex Java app running, which just never sounded appealing to me.
Webdriver.IO wraps Selenium, which means you can run test scripts on all browsers. It allows you to easily integrate it with multiple testing frameworks, such as Appium, to run test scripts against Android or iOS mobile phones. WebDriverIO uses Node.js common libraries. For example:
This allows us to assert and validate the test. This library is not only for Webdriver but also used in React.js, Angular.js, and other frameworks’ unit testing.
This module is one of my favorites. Instead of writing a bunch of workflows from scratch, Lodash gives you an opportunity to try an already defined, modern JavaScript utility library.
Starting with WebDriver.IO
To start with WebDriverIO, the first prerequisite is to install NPM and Node.js. Follow the link below to set it up.
After successfully setting up Node.JS, it's time to install WebDriverIO CLI. Type the following command in the command prompt:
npm install @wdio/cli
The next step is to set WebDriver configurations. This command was introduced in WebDriverIO v6 and helps automation engineers to define things such as the automation backend, framework, reporting tool, etc. through a user-friendly wizard.
wdio config
Cool! We are now ready to write our first test script.
Creating the first test script
I highly recommend using the Visual Studio Code editor to write your code. Before proceeding with test execution, it is important to store all your test scripts in one place. So, create a directory called "test" in the project folder, navigate to the test folder, and create a specs folder. Now create a JavaScript file in the specs folder and write your test script in that file and save it.
Page Object Models are commonly used in Web UI Automation for structuring automation tests. In this design pattern, the pages or views of an application should be separated from the test case logic. This is done by creating separate classes or objects to represent the important UI elements contained on each page. This object contains information on how to find an element within a page/view or execute a popular user flow, such as entering and submitting text in a search box. This approach allows one to write reusable and maintainable code.
Example:
Here we can see that all UI elements have methods that are readable and maintainable.
Here is a simple example of a test script. We use Page Object models in order to identify elements in a web page. Then use the describe() and it() methods to write test cases. At the end of each test case, we should validate the expected results by calling the Chai.js expect method.
WebdriverIO is a JavaScript-based automation framework that wraps Selenium, allowing developers to run automated test scripts across multiple browsers and integrate with mobile testing frameworks like Appium.
How do you install WebdriverIO?
You need Node.js and NPM installed first. Then, install the WebdriverIO CLI using the command: npm install @wdio/cli. After installation, you can configure your project using the WebdriverIO configuration wizard by running wdio config.
What is the Page Object Model in WebdriverIO?
The Page Object Model (POM) is a design pattern that separates page-specific elements and interactions from test case logic. This makes test scripts more reusable, readable, and maintainable.
How do you write your first test script?
Create a test folder in your project, add a specs folder inside it, and write JavaScript test files. Use describe() and it() methods to define test cases, and Chai.js’ expect method to validate expected results.
What libraries or tools complement WebdriverIO?
Popular tools include the Chai Assertion Library for validating tests and Lodash for utility functions. These help simplify test logic and increase maintainability across projects.
AI is changing software development.
The Engineer's AI-Enabled Development Handbook is your guide to incorporating AI into development processes for smoother, faster, and smarter development.
Enjoyed the article? Get new content delivered to your inbox.
Subscribe below and stay updated with the latest developer guides and industry insights.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.