Running a Test Against Multiple Environments (Using BaseURL)
I have multiple test environments in which to execute my test scripts. The server URL is different for each environment. How can I avoid rewriting all of my tests from scratch to make them work with a different server URL?
Test Studio allows you to create URL-relative tests with the concept of the BaseURL property. The BaseURL property is the non-relative part of the URL that is set as a global setting for your entire test. A simple example:
Let's say we want to run the same test against the application MyApplication deployed on two servers: http://Server1 and http://Server2.
First we set the BaseURL for the project to "Server1". Now start recording. You'll notice that when you record a NavigateTo step the BaseURL is stripped from the URL. For instance:
If you open your application from the URL http://Server1/MyApplication this step will be recorded as Navigate to: '/MyApplication' - the base URL is removed.
After you've finished recording you can change the BaseURL from your project settings and execute the test against a different URL. More importantly, Test Lists have their own BaseURL property. This property is inherited by the project settings by default, but you can change it. In this way you can create different Test Lists to run the same tests against different servers. Below you'll find a specific description for the Standalone and Visual Studio Plugin versions.
Set the BaseURL from the Project Settings. From the Project tab, click the Show button in the Setting ribbon:
In the Project Settings menu, click Recording Options on the left. You can set the BaseURL here:
Once you record a test, go to the Test Lists tab and create a new test list. Now you can set the BaseURL for this test list. Click Edit Settings:
The Edit Test List Settings menu appears. Scroll to the bottom and find the BaseURL property under the Navigation heading:
You can create multiple test lists in the fashion, each running against a different BaseURL.
Visual Studio plugin
Set the BaseURL from the Project Settings menu just like in the Standalone version. Locate this button in the toolbar:
Note: Quick Execution disregards the BaseURL setting - you'll have to execute the test from the Test View.
In the VS Plugin you'll need to create different test settings files for each test list. Then you can execute your test lists with MSBuild and feed them the correct test settings file as an MSBuild parameter. You can also execute a test list with a custom test settings file from the command line using MSTest.
To create a custom Test Settings file:
- Open the Local.testsettings file.
- Click Telerik Test Studio on the left and then the Web tab.
- Locate the BaseURL property under the Navigation heading.
- Click "Save As" rather than "Apply" to save this file under a new name.
- You can now use this newly created Test Settings file.
BaseURL Test Step Property
The BaseURL setting in Recording Options is used while recording and for Quick Execution:
- When recording "Navigate to" steps, if the actual BaseURL matches the BaseURL recording options setting, Test Studio automatically splits the recorded URL into NavigateURL and BaseURL. If the BaseURL does not match, no split with take place. The recorded BaseURL will be left empty.
- During Quick Execute, if the BaseURL property of the test step contains a non-empty string, the BaseURL setting from Recording Options will be pre-pended to the NavigateURL property and the "Navigate to" step will used that combined URL.
The BaseURL property in the test step holds the value that was seen during recording:
- When non-empty, it will be replaced when the test executes.
- When empty, it tells the execution engine not to use the BaseURL setting (i.e., do not combine NavigateURL with BaseURL from either Recording Options or Execution Options).
The BaseURL property in the Execution Options only effects normal test execution:
- When the test step's BaseURL property is non-empty, this value will be pre-pended to the NavigateURL setting of the test step. The combined URL will be used by the "Navigate to" step.
This combination provides flexibility during recording and playback so that some test steps will automatically take advantage of the BaseURL setting, while other test steps can still have a static URL.
When a recorded test step interacts with an element inside an iFrame, by default that iFrame is mapped with its full URL. There is an option, however, to specify that the URL of the iFrame is relative to the BaseURL. Highlight the Frame node in the Elements Pane and locate the UsesBaseUrlHost setting in the Properties Pane.
Let's say we want to run a test against the same application, but on different servers: http://Server1/myApp and http://Server2/myApp. Also say there's an iFrame in the app with the following source: http://Server1/myApp/frame1.aspx. Simply set the frame's UsesBaseUrlHost property to True. When you switch the BaseURL before executing the test, Test Studio will automatically swap the BaseURL portion for the frame under the hood.
When set to True, the frame uses the host portion of the project's BaseURL setting.
Let's say we want to run a test against the same application, but under different paths on the same server: http://Server1/Dev1/Folder1/ and http://Server1/Dev2/Folder1/.
Modify the BaseURL property under FrameInfo. Start with '^/' to substitute the test's BaseURL in place of the caret (^). In this case the test's BaseURL defined in the Project Settings would be http://Server1/Dev1 or http://Server1/Dev2.