HomeWebDriverIO

WebDriverIO – Pause Command

WebDriverIO – Pause Command

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

WebDriverIO – Pause Command

Pause Command is used to pause execution for a specific amount of time. In simple terms, Pause command helps browser to pause for certain amount of time based on the time passed by the user as an argument. Sometimes page load takes more than usual time because of server response or of any random issue occurred at run time. Therefore, pause command helps browser to stop execution of the next action written in the code till the time page gets loaded based on the amount of time passed by the user.

Usage: – browser.pause(milliseconds)

Where milliseconds is parameter which should be of number type and should be in milliseconds.

Pre-requisite: Have ‘Visual Studio Code’ IDE installed in your machine (Click here to install if not installed in your machine)

Here is the small Exercise of clicking on a button and making browser to pause for 25 seconds before exiting, using pause command of WebDriverIO.

Using Pause Command

First, I will demonstrate the exercise where we will open URL in browser window, then click on a button and make browser pause for 25 seconds till the time the text present above the button get disappeared before exiting the browser using pause command, followed by practically demonstrating the WebDriverIO Automation code for achieving it.

Exercise:-

1)  Navigate to http://omayo.blogspot.com/ 

2)  Scroll down to the button on which we need to click on.

3) Text appearing previously should get disappeared and browser window should exit.

Practical Demonstration:

Following are the Steps to Perform above Exercise (i.e. to click on a button and making browser to pause for 25 seconds till the text got disappeared before exiting browser window) using WebDriverIO Automation code in ‘Visual Studio Code’ IDE:

Pre-requisite: Download the Project from here (Click here to Download) and Unzip it.

1)  Open Visual Studio Code on your system.

2)  Click on File and Select Open Folder. Select the project folder on which your workspace is present.

3)  Expand ‘test’ from the Explorer, right click on the displayed ‘specs’ and select ‘New File’ option as shown below:

4) Give any name of the newly created file say “Pause_Command_test.js” and copy the below given code into the newly created file as shown below and save the file:

The following is the WebDriverIO sample code to clicking on a button and making browser to pause for 25 seconds before exiting on ‘Omayo.blogspot.com’ application.

You can understand this code, by reading the comments provided in the below code:

Copy the code from here:-

describe('This Example show usage of pause command in webdriverio', () => {
    it('should click on button and pause browser for 25 seconds before exiting', ()=> {
    browser.url('http://omayo.blogspot.com');
    const UL = $('#HTML25 > h2'); 
    UL.scrollIntoView(); // scroll till UnOrderedlist so that Button to click comes under browser view 
    $('#alert2').click();// clicking on button
    browser.acceptAlert() //Accepts the alert which gets open
    browser.pause(25000); //make browser to pause for 25 seconds till text got disappeared.
    });
});

5) Click on ‘wdio.conf.js’ to open in the IDE, and make sure the Test file name is updated properly and browser name should be changed from firefox to chrome in this file as shown below and save it:

6) Click on Terminal and Open New Terminal.   

7) By Default, Powershell Terminal will open, change it to git bash as shown below:

8) Open Another Terminal in the same way we did in the step 6 and run below command in terminal

.\node_modules\.bin\wdio .\wdio.conf.js

Observe that the ‘Pause_Command_test.js’ will get executed successfully, the chrome Browser will launch, and open URL given in code and respective action will be taken by WebDriverIO Automation code.

And also, the result will be displayed as ‘Passed’ in the terminal as shown below:

This is how, we can take help of Pause Command of WebDriverIO to make browser pause for the time we want based on the argument passed before executing next action. Likewise, I will explain other commands to perform different operations on Web Pages using WebDriverIO in the upcoming Articles.

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 contribute to the Software Testing Community in all possible ways.

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

­

Comments (0)

Leave a Reply

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

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp