How to Get the Current URL in WebDriver IO with JavaScript?
Obtaining the current URL of a webpage is crucial in various testing scenarios, such as verifying successful navigation to the correct webpage, redirect operations, or the URL structure in dynamic web applications. WebDriverIO, an open-source utility for Node.js, provides an effortless method to achieve this in your automation testing scripts. This article focuses on the process of obtaining the current URL using WebDriverIO in JavaScript.
Retrieving Current URL Using 'getUrl' Method in WebDriverIO
The WebDriverIO API provides the 'getUrl' method that returns the current URL of the webpage. Here's an example where we navigate to the Wikipedia Main Page and then retrieve the URL:
const currentUrl = await browser.getUrl();
Here is an example test that uses the above code snippet.
This code fetches the current URL using the 'getUrl' method. Remember, 'getUrl' is an asynchronous operation and should be awaited for its completion.
Leave a reply
Your email address will not be published. Required fields are marked*