Is it possible to have a scenario outline where each example runs in a different URL? For example, if the first column in the examples table is some kind of two digit/character code, open a different starting URL based on that value?
Asked
Active
Viewed 2,062 times
2 Answers
2
Yeah sure. Why not just have a step which sets the URL, assign the URL to be used to some variable (either in the class, in the ScenarioContext.Current
, or in a custom context object) and then use this URL in all your calls. In on my phone so formatting is a pain, but something like this:
Given I'm using the site '<site>'
When I login
Then something should happen
Examples:
|site |
| aaa.com|
| bbb.com|
Then in the given step just record the URL and use that base URL to build the full URL in the when step.
Your steps class could look something like this.
[Binding]
Public class Steps
{
Private string baseUrl;
[Given ("I'm using the site '(.*)'")]
Public void GivenImUsingTheSite(string baseUrl)
{
This.baseUrl=baseUrl;
}
[When ("I log in")
Public void WhenILogIn()
{
String URL=baseUrl + "\login";
....login
}
}

Sam Holder
- 32,535
- 13
- 101
- 181
0
Given the following scenario outline:
Scenario Outline: Each page has an help option
Given I am on the '<PageName>' page that has id '<Id>'
Then I expect an help option
Examples:
| PageName | Id |
| Home | 0 |
| Products | 5 |
| FAQ | 42 |
Then you can make a step like this:
[Given(@"I am on the '(.*)' page that has id '(.*)'")]
public void GivenIAmOnThePageThatHasId(string friendlyName, string id)
{
// pageids are shaped like 'http://www.example.com/pageid?4'
var myUrl = @"http://www.example.com/pageid?" + id;
Console.WriteLine("Navigating to the {0} page following url {1}", friendlyName, myUrl);
NavigateToUrl(myUrl);
}

AutomatedChaos
- 7,267
- 2
- 27
- 47
-
The thing is we are testing more than one website, so the websites would be like: http://www.aaa.com http://www.bbb.com http://www.ccc.com They would be running the same steps, just different starting URLs before the login step. – AutomatedOrder Aug 28 '15 at 15:35
-
We use [the app.config](http://stackoverflow.com/questions/13043530/what-is-app-config-in-c-net-how-to-use-it) to differentiate settings between test environments. If you connect a username with a testenvironment and a testenvironment with a set of parameters (like URLs), every user can have other settings and change the test environment in a blink of the eye. In the `[BeforeTestRun]` hook, you can get the username with `Environment.UserName` and search for the correct settings in the configfile. Use those settings in a static object or inject them in the `ScenarioContext`. – AutomatedChaos Aug 28 '15 at 18:29