AutoTester213
AutoTester213

Reputation: 2871

Run BeforeTestRun and AfterTestRun only once using specflow with Selenium

I have seen the question here How to execute before and after test run only once in parallel execution of specflow - although I am unable to understand how to run the Hooks just once in parallel

I am using Specflow+ Runner as my test provider, my thread count is 3, I have a BeforeTestRun hook that creates my test data, I want to execute that Hook only once, but by default BeforeTestRun is ran on each thread, I have also looked at the example here: https://github.com/SpecFlowOSS/SpecFlow.Plus.Examples/tree/master/CustomDeploymentSteps,

But I am unsure how it works, could anyone help me out on this one.

[BeforeTestRun()]
public static void BeforeTestRun()
{
    Console.WriteLine("test");
}

Output is:

test
test
test

My Default.srprofile looks like this

<?xml version="1.0" encoding="utf-8"?>
<TestProfile xmlns="http://www.specflow.org/schemas/plus/TestProfile/1.5">
    <Settings projectName="TestAutoProject" />
    <Execution stopAfterFailures="2" testThreadCount="3" testSchedulingMode="Sequential" />
    <TestAssemblyPaths>
        <TestAssemblyPath>Test.dll</TestAssemblyPath>
    </TestAssemblyPaths>
    <Targets>
        <Target name="IE">
            <Filter>Browser_IE</Filter>
            <DeploymentTransformationSteps>
                <EnvironmentVariable variable="Test_Browser" value="IE" />
            </DeploymentTransformationSteps>
        </Target>
        <Target name="Chrome">
            <Filter>Browser_Chrome</Filter>
            <DeploymentTransformationSteps>
                <EnvironmentVariable variable="Test_Browser" value="Chrome" />
            </DeploymentTransformationSteps>
        </Target>
        <Target name="Firefox">
            <Filter>Browser_Firefox</Filter>
            <DeploymentTransformationSteps>
                <EnvironmentVariable variable="Test_Browser" value="Firefox" />
            </DeploymentTransformationSteps>
        </Target>
    </Targets>
    <DeploymentTransformation>
        <Steps></Steps>
    </DeploymentTransformation>
</TestProfile>

Upvotes: 1

Views: 796

Answers (0)

Related Questions