Reputation: 43
I'm trying to use multiple tags on one scenario but it ends up opening a window for each tag, which causes problems during the [AfterScenario]
step. For an example I have a scenario of:
@Tag01 @Tag02
Scenario Outline: User Log In
Given I'm using the <ABC>
Given I Log in as AutomatedUser
Examples:
| ABC |
| SiteOne |
| SiteTwo |
And my stepbase.cs file before scenario:
[BeforeScenario("Tag01", "Tag02")]
public static void BeforeScenario()
{
StepBase.CreateBrowser(ConfigurationManager.AppSettings["BrowserType"]);
Console.WriteLine("selenium open Called");
}
Is there a way to use multiple tags without it opening a window for each tag?
Upvotes: 4
Views: 2514
Reputation: 32936
What behaviour do you expect?
if you have this:
@Tag01
Scenario Outline: User Log In
... etc
do you expect the BeforeScenario
to be invoked? Or only if you have both tags?
By the sounds of your question you want it invoked if either of the tags exist, but only once.
I think you'll have to handle this yourself. Something like this should do it:
public class Hooks
{
private bool BeforeScenarioDoneAlready{get;set;}
[BeforeScenario("Tag01", "Tag02")]
public void BeforeScenario()
{
if (!DoneBeforeScenarioAlready)
{
StepBase.CreateBrowser(ConfigurationManager.AppSettings["BrowserType"]);
Console.WriteLine("selenium open Called");
BeforeScenarioDoneAlready=true;
}
}
}
if you want it to only be done if both tags exist then you can check this in your BeforeScenario method:
[BeforeScenario()]
public void BeforeScenario()
{
if(ScenarioContext.Current.ScenarioInfo.Tags.Contains("Tag01")
&& ScenarioContext.Current.ScenarioInfo.Tags.Contains("Tag02"))
{
StepBase.CreateBrowser(ConfigurationManager.AppSettings["BrowserType"]);
Console.WriteLine("selenium open Called");
}
}
Upvotes: 4