Note: This example program is without any testing framework.
1. How to install?
WebdriverIO is a ‘npm’ package and runs on ‘Node.js‘. So, we need to install ‘Node.js’ and ‘npm’ in our machine before installing WebdriverIO.
Step by step process of installing ‘Node.js’ and ‘npm’ in our Windows / Mac machines.
After installing Node.js, run the below command to create a Project folder and navigate to it.
$ mkdir WebdriverIOAutomation $ cd WebdriverIOAutomation
Run the below command to install ‘webdriverio’.
npm install webdriverio
2. Project Structure:
Run the below command to create specs folder.
mkdir -p ./test/specs
3. How to write?
Create a WithoutWdioClient.js file in WebdriverIOAutomation/test/specs folder
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome' //Browser choice
}
};
webdriverio
.remote(options) //Passing configurations
.init() // Initiating webdriverIo
.url('http://www.google.com') //Navigates to google.com
.getTitle().then(function(title) { // Gets the title of the page.
console.log('Title was: ' + title); // Prints the title of the page.
})
.end();
You can mention browser name as ‘chrome’ or ‘firefox’ based on your choice.
4. How to Run?
Run the below command in CommandPrompt/Terminal to install selenium server utility.
npm install -g selenium-standalone
Run the below command in CommandPrompt/Terminal to update selenium standalone server and browser drivers to latest versions.
selenium-standalone install
Run the below command in CommandPrompt/Terminal to run selenium server.
selenium-standalone start
Open a new CommandPrompt/Terminal and run the below command to execute WebdriverIo test.
node ./test/specs/WithoutWdioClient.js
You should see a browser opened and navigated to google website and closed. It’s very quick.
Observe that Title was: Google
printed in CommandPrompt/Terminal.