Two-tag script script opens two windows

I try to use several tags for one script, but in the end a window opens for each tag, which causes problems during the step [AfterScenario]. For example, I have a script:

@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 the script:

[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 opening a window for each tag?

+4
source share
1 answer

What behavior do you expect?

if you have this:

@Tag01
Scenario Outline: User Log In
... etc

Do you expect that to be BeforeScenariocalled? Or only if you have both tags?

By the sounds of your question, you want it to be called if any of the tags exist, but only once.

, . - :

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;
        }
    }
}

, , , BeforeScenario:

[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");
    }
}
+4

Source: https://habr.com/ru/post/1611833/


All Articles