WebDriverIO – Run your first automation script

WebDriverIO – Run your first automation script

<<Previous Post               <<Complete WebDriverIO Tutorial>>               Next Post>>

WebDriverIO – Run your first automation script

The following are the steps you need to follow for executing your first Test Automation Script using WebDriverIO tool:-

Step#1:  Install WebDriverIO

If you haven’t roaming around with WebDriverIO, I’ll quickly explain that it’s a functional test automation framework. (Click here to learn WebDriverIO from basics)

It allows you to script out page actions to take in a browser, and validate that the actions had the desired effect.

Prerequisites required to Install WebDriverIO

1) Node.js version v10.15.3  ( To install Node.js for windows click here)

2) NPM version 6.4.1  (It automatically gets installed on installing the above Node.js)

3) GIT Bash version 2.21.0  (To install GIT Bash for windows click here)

Next steps before installing WebDriverIO

Once all the above prerequisites are satisfied or installed or configured, follow the below steps:-

Create a folder ‘Tutorials’ on your desktop (You can create folder with any name)

Open the Git Bash from the above created folder (In our case ‘Tutorials’ folder)

webdriverio - TutorialsFolder

Trigger the below command in Git Bash Window:

npm init -y

The above command will create a default package.json file in the ‘Tutorials’ folder.

Attached Screenshot for Reference:-


Now Install WebDriverIO

Run the below command in Git Bash command prompt:

npm install webdriverio

Download GeckoDriver

To Download Geckodriver (Click here to know how to Download GeckoDriver for Windows and Configure it)

Note: You must have latest Firefox installed to use latest Geckodriver.

Setup GeckoDriver

Now setup GeckoDriver before moving to the next step (Click here to setup Geckodriver)

Copy the downloaded geckoDriver.exe file into the Tutorials folder:

Copy the geckoDriver.exe file into the Tutorials folder

Start Geckodriver by running in Git Bash:

Start Git bash from the Tutorials folder where geckoDriver.exe file is available.

Trigger the below command in Git Bash Command prompt:

$ geckodriver --port 4444

This will start Geckodriver on localhost:4444.

You will not see any output.

And keep this Git Bash Window running in the background and open a new Git Bash command window from the Tutorials folder.

Create Test File

Create a text file, add the below sample code and save it as test.js:

const { remote } = require('webdriverio'); (async () => { 
const browser = await remote({ logLevel: 'error', path: '/', 
capabilities: {browserName: 'firefox'} });
await browser.url('http://tutorialsninja.com/demo/'); 
const title = await browser.getTitle(); 
console.log('Title was:' + title); 
await browser.deleteSession(); 
}) ().catch((e) => console.error(e));

Run your test file

Run the test script by calling in Git Bash window:

$ node test.js

This should output the following:

Title was: The Ninja Store

Yay, Congratulations! You’ve just run your first automation script with WebdriverIO.

Next Steps:

> To learn more about WebDriverIO, continue to the next post (Click on Next Post link below)

> Check complete WebDriverIO Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Ajay Lunia 

Connect to me on LinkedIn (Click here)

On a mission to help the Software Testing Community in all possible ways.

<<Previous Post               <<Complete WebDriverIO Tutorial>>               Next Post>>

Comments (2)

Leave a Reply

Your email address will not be published. Required fields are marked *