If you’re testing a web application, it would naturally be best to test it with not only one but with all of the most popular browsers (cross-browser testing).
This blog post will show you how to record your automated tests using a browser and then automatically execute the recorded tests with different browsers. With Ranorex v3.2 (and higher) you can run your tests in Internet Explorer, Mozilla Firefox, Google Chrome and Apple Safari.
Sample Test Suite Project
To demonstrate how to perform a multiple browser test, we will generate a small sample which enters data in our VIP Database Test Web Application, a small web application having the same functionality as the VIP Database you might know from our user guide.
Note: The sample test suite project is also included with the Ranorex installation package (shown on the startpage of Ranorex Studio).
First of all we’ll create a Test Case holding two Recordings, one for opening and one for closing the browser as setup and teardown modules.
Now we add a “OpenBrowser” action to the OpenBrowser Module with “http://www.ranorex.com/web-testing-examples/vip/” as Url and e.g. “IE” as browser.
As next step we add a recording module validating the status String on connecting and disconnecting.
The recording module simply
- validates, that the status text equals “Online”,
- validates, that the status text equals “Offline”,
- connects again,
- confirms to connect in the pop up window
- and validates, that the status text equals “Online” again.
Make sure that the RanoreXPath of your App Folder does not include any browser specific equation like “browsername=…”.
Make also sure to have two repository items representing the connection status text, one for “Online” and one for “Offline”. This allows you to overcome issues with delaying validation steps. In our application it takes some time that the status text changes from “connecting…” to “Online”. To make the Validation work, we can simply add the actual validation into the RanoreXPath and only validate the existence of the status text in our web page. By doing so, we are using the search timeout of the repository item to wait for the status text to change.
Additionally to the TestConnection recording, we will generate a recording for adding VIP’s to the database. This recording will be added to a new Test Case as we want to data driven add VIP’s and do not want to open and close the browser and testing the connection with each iteration of adding a new VIP.
The recording might look something like this:
As we want to make our test data driven, we have to add variables which can be bound with the data from our data source.
The key sequences for first and last name contain the variables $FirstName and $LastName.
To select the category, we have to add a SetValue action and set the TagValue to the variable $Category.
The gender can be set by adding a variable to the RanoreXPath of the corresponding repository item.
Additionally, we validate the VIP count against a variable $VIP_Count.
After generating the recording, we create a data source for the Test Case Add_VIP’s and bind the data tables to the variables of the recording AddVIP.
As last step we add a Close Application action to the CloseBrowser Module with the application folder of the web application as repository item.
Now we can execute our Test Suite Project, which:
- opens the web application in Internet Explorer in the setup region,
- performs connection tests,
- adds 3 VIPs following the data driven approach (the data for the 3 VIPs are stored in a simple data table),
- validates the count of the VIPs stored in the web application
- and closes the browser in the tear down region.
To perform these steps not only for IE but also for the other 3 browser which are supported, we first make the browser which will be started in the Recording “OpenBrowser” variable.
Therefore open the recording “OpenBrowser” and edit the browser which should be started. Now choose “As new Variable…” instead of “IE” and add a new Variable called BrowserName.
After that, add a new simple data table to the Test Case “Add_VIP_and_Validate”, holding the names of the different browsers and bind the data connector to the variable “BrowserName”.
After making the browser variable that way and binding this variable to a table holding all supported browser names, you can execute your test script for all supported browser.