Skip to content
Go back

Test Automation - Review On Selenium WebDriver JavaScript CLI

Published:

Introduction

In this article, I will review a tool called Webdriver IO REPL interface.

The tool can be used for debugging tests, finding elements, getting to know selenium and Web automation.

In addition, we will install Selenium Grid server locally - the server is required to be up and running as a prerequisite for using this tool.

The tool is built on a framework called WebdriverIO.

Tool advantages

Tool installation

Run the following command on our command line:

npm install selenium-standalone@latest –g
selenium-standaloneinstall

The use of “-g” indicates that we want the installation to be globally available on a computer rather than a specific project.

npm install -g webdriverio
Selenium-standalone start

We can see that the server is running successfully at port 4444.

No alt text provided for this image

The server will be available to us at:

http://localhost:4444/wd/hub/static/resource/hub.html

This is what the server looks like:

No alt text provided for this image

The tool starts by running the following command:

wdio repl chrome

Note that Chrome is used as a browser parameter. If you type the command without this parameter and if Firefox is installed on your computer, Firefox should open by default.

This is how it looks after the tool has started:

No alt text provided for this image

Test case #1

The first test case is attached in the following screenshot:

No alt text provided for this image

As we can see, we started navigating to the Google site, storing the page title as a variable and then running an assert that checks that the page title is equal to the text I expect - in this case there is no match and therefore an error is thrown.

Test case #2

We will use the “getAttribute” command to extract the “src” of the Google image. The function accepts two parameters, the Selector and the Attribute that we want to extract.

The Console.log command is invaluable for us when we want to print to the terminal, as in the following case:

No alt text provided for this image

In conclusion

In this article, we reviewed the REPL tool (Read-Eval-Print-Loop for more reading on the concept here), its advantages, installation and using the tool for writing 2 simple test cases. In order to experience WebdriverIO in writing your JavaScript tests, I recommend starting with the next video to install a full workspace. Then, continue to their excellent Developer Guide here.

Happy testing!


Suggest Changes

Have a challenge? Let's Talk


Previous Post
Guide - ADB Commands For Mobile Software Testers
Next Post
Test Automation- Multiple Asserts Using NUnit Testing Framework