Automation testing of business applications built on different platforms is essential to deliver high-quality software within increasingly shorter timelines. Selenium testing has always been the first choice for automation testing of web applications. When conducted in tandem with WebdriverIO integration, one can increase the scope of Selenium tests from only web platforms to the native iOS devices as well.
WebdriverIO offers third-party integrations that make testing and debugging a lot more efficient. It’s easy to write script and robust architecture that is based on RESTful services makes it a good choice for automation testing of applications on native iOS devices.
Thus, testers can achieve much greater test coverage with WebdriverIO Selenium Automation Testing.
Table of ContentsWebdriverIO is an open-source testing automation framework written in JavaScript and running on NodeJS. It is particularly useful for testing web applications and native mobile applications for iOS-enabled devices. Its support for both Behavior Driven Development (BDD) and Test Driven Development (TDD) makes it a highly preferred choice for automation testers.
WebdriverIO is built over NodeJS, which is an implementation of the JSON Wire Protocol. Packaged into npm, it conducts communication using NodeJS, which is open-source and widely used for application development. It uses RESTful architecture to conduct automation testing.
The user writes the test script in JavaScript using the WebdriverIO library, where the Service request is sent via NodeJS as an HTTP command. It uses JSON Wire protocol, and the services module forwards the request to the browser.
Upon receiving the command, the browser performs the user actions, which tests the validity of the application functions.
WebdriverIO Architecture
A common reason to use WebdriverIO is its ability to test native mobile applications for iOS-enabled devices. It has a simple structure, and one can write the test scripts concisely – a matter of great convenience for QAs.
WebdriverIO can be easily integrated with third-party testing solution providers like BrowserStack. This makes it easy for the QA to leverage additional functions like recording tests, using real devices and browsers on the cloud, test reporting, etc.
WebdriverIO allows QAs to add new custom commands in addition to those already available by default. By calling the addCommand function, one can add new custom commands that can make testing easier.
Consider the following example, which uses the addCommand function to print the URL of a web page.
browser.addCommand('getUrlAndTitle', function(customVar) { // `this` here means the `browser` scope for which the new command is added return { url: this.getUrl(), customVar: customVar } })
Before exploring how to write WebdriverIO tests, let’s understand how to set up WebdriverIO. First of all, the prerequisites mentioned below have to be met.
Prerequisites for WebdriverIO
$ node -v $ npm -v
npm install webdriverio
npm install -g selenium-standalone
selenium-standalone install
selenium-standalone start
Users can configure by choosing from the given options as per their requirements. This allows them to choose where to launch the tests, location of the automation back-end, the framework, location of test specs, reporter, and whether to run the WebdriverIO commands synchronously or asynchronously.
Once WebdriverIO is set up, and the test script file is created, write the test script using JavaScript. The following code must be written in the webdriverioTestScript.js file created earlier in the specs folder.
Here’s the scenario to be automated:
describe('Google Search Test', () => { it('should have the right title', (done) => { await browser.url('https://google.com/') search_box_element = $('[name=\'q\']') search_box_element.setValue("BrowserStack\n") expect(browser).toHaveTitle("BrowserStack - Google Search"); //title of the launched webpage is printed in console as output const pagetitle = browser.getTitle() console.log(‘Title of the webpage is -’ + pagetitle) }) })
Once the test script is ready, it can be executed by running the following command on the Command Prompt:
node ./test/specs/webdriverioTestScript.js
Upon running the above test script:
Run your first Selenium Test for Free
Criteria | WebdriverIO | Selenium |
---|---|---|
Programming Language | JavaScript | Java, Python, Groovy, Scala, C#, Ruby, Perl, etc. |
Used for | Automating Browsers and Native Mobile Applications for Testing | Automating Browsers for Testing |
Accessibility | Open Source | Open Source |
Support | It is relatively new and does not have extensive support from the community | Well supported by most browsers and versions with a large community of developers across the globe |
Custom Command | Allows the tester to add custom commands in the test script by calling the addCommand function | Does not have the option to add custom commands. However, it offers a number of tools that can be integrated for enhanced testing coverage |
When to use | While testing native iOS mobile applications | While testing web applications, parallel testing, regression testing, and cross browser testing |
Architecture | Layered architecture built over NodeJS that is an implementation of JSON Wire Protocol that is packaged into np | Layered architecture based on JSON Wire Protocol |
Test Runner Frameworks Supported | Mocha, Jasmine, and Cucumber | Mocha, Cucumber, Jest, Jasmine, Protractor, and WebDriverIO |
CI/CD Integrations | Jenkins, Docker, and Bamboo | Jenkins, Bamboo, TeamCity, Azure Pipelines, CircleCI, Bitbucket Pipeline, Travis CI, Github Actions, and GitLab CI/CD |
Test automation is crucial for testers to keep up with the growing demands of faster delivery and optimal software quality. Selenium automation testing allows testers to achieve precisely this, thus leading to the creation of better applications in shorter durations.
Bear in mind that WebDriverIO automation works best when testing websites on a real device cloud. Doing so is the only way to ensure the complete accuracy of results. So, always opt for real device testing to comprehensively verify website performance, cross browser compatibility, and the quality of user experience it offers.
ncG1vNJzZmivp6x7o77OsKqeqqOprqS3jZympmeXqralsY6wnJucop7Dpr7IqGStraSkv6qty2adqKpdqLKtsc2irKZlkarBsLnAraCopg%3D%3D