HomeWebDriverIO

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 (3)

  • hi
    i am facing below error after
    $ geckodriver –port 4444
    bash: geckodriver: command not found

    Reply
  • Hi Ajay,

    I am learning WebdriverIO with this awesome tutorial of yours but facing the following error:

    1. I set path to geckodriver in system
    2. In 1 gitbash command promp I run geckodriver –port 4444 and in a separate gitbash command promp, I am running node test.js
    3. I could notice firefox broweser launching but then it got closed quickly(I did not see url getting opened)
    4. I get the following output in gitbash command prompt

    $ node test.js
    Title was:Your Store

    5. Following is the log in 1st gitbash command prompt

    $ geckodriver –port 4444
    1600029216409 geckodriver INFO Listening on 127.0.0.1:4444
    1600029240079 mozrunner::runner INFO Running command: “C:\\Program Files\\Mozilla Firefox\\firefox.exe” “–marionette” “-remote-debugging-port” “59412” “-foreground” “-no-remote” “-profile” “C:\\Users\\CXXXXXXX\\AppData\\Local\\Temp\\rust_mozprofileTlaEcg”
    JavaScript error: resource://gre/modules/URIFixup.jsm, line 271: NS_ERROR_FAILURE: Should pass a non-null uri
    console.error: SearchCache: “_readCacheFile: Error reading cache file:” (new Error(“”, “(unknown module)”))
    JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can’t find profile directory.
    1600029247090 Marionette INFO Listening on port 59414
    1600029250545 Marionette INFO Stopped listening on port 59414
    JavaScript error: resource://gre/modules/UrlClassifierListManager.jsm, line 691: TypeError: this.tablesData[table] is undefined
    JavaScript error: resource://gre/modules/NewTabUtils.jsm, line 686: NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsINavHistoryService.asyncExecuteLegacyQuery]
    console.log: “RemoteSettingsWorker error: Error: Can’t import when we’ve started shutting down.”

    ###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost

    ###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/re

    Reply

Leave a Reply

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