In our last tutorial, we learned basics of writing a coded step in Telerik Test Studio, in this tutorial we will focus on different commands and actions that Test Studio allows the user to perform on the browser.
In this tutorial, we will discuss the important browser navigation commands that are present in the Test Studio. Here we will also discuss various commands that can be used in our day to day automation testing work.
All the browser methods can be accessed by using, ActiveBrowser keyword. Using this keyword will open up the public methods of the ActiveBrowser, as shown below:
Let’s have look at some of the methods that are used frequently while creating automation suite.
Using Navigate To command
This command loads a new webpage in the currently active browser window. It accepts a string as a parameter.
Command: ActiveBrowser.NavigateTo(“string URL“);
It is similar to the Navigate to method we use from the Step builder. It is advisable to use a full URL for accessing any page. To access any page just replace the string URL with full URL of the web application you want to automate.
Using Page Title Command
This method fetches the title of the current webpage opened in the browser. This method accepts null as a parameter and returns a string value.
Command: ActiveBrowser.PageTitle;
As we have return type defined as a string value, then the output needs to be saved in a string variable.
Once the title has been stored in the string variable, the user can use it to perform any validation or operation needed. For example: we can perform an assert operation to validate if the title of the webpage is equal to expected string value.
Assert.AreEqual(” put expected title of the page here“, pageTitle);
This asserts statement will compare the current page title with the expected page title variable.
Using Forward command
This method mimics the click event on the forward button in the browser. This command has no parameters and doesn’t return anything.
Command: ActiveBrowser.GoForward();
This command allows the user to navigate webpage forward by one page based on the browser’s history.
Using Backward command
This command mimics the backward button click event on the active browser. Similar to the GoForward command this command also doesn’t pass any parameter and returns nothing.
Command: ActiveBrowser.GoBack();
This command allows the user to navigate to the previous webpage in the browser based on the browser history.
Using Browser Refresh command
This command refreshes the current webpage. Similar to forward and backward command it neither accepts any parameter not returns anything.
Command: ActiveBrowser.Refresh()
It performs a similar function such refreshing the webpage using browser button or by pressing an F5 key from the keyboard.
These were the basic browser commands present in the Test Studio for performing different functions on the active browser. There are different other browser commands available in the Test studio that can be invoked by using active browser keyword. You can work your way through them by typing ActiveBrowser followed by Dot (.). This will fetch all the commands that we can use with the ActiveBrowser keyword.