1

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>
julianstark999
  • 3,450
  • 1
  • 27
  • 41
AutoTester213
  • 2,714
  • 2
  • 24
  • 48
  • What do you want to do once for every TestRun? Also in which part are you unsure of the custom deployment steps? – Andreas Willich Jun 17 '20 at 11:32
  • @AndreasWillich I want to create some pre-test data in my TestRun at the start, I am not sure what/where to reference the deployment steps, I can see the '' i guess we have to put it in there but not sure what, Is a method/class that i need to reference? – AutoTester213 Jun 17 '20 at 12:04
  • Your custom deployment step has to be in a separate class library (https://github.com/SpecFlowOSS/SpecFlow.Plus.Examples/tree/master/CustomDeploymentSteps/CustomDeploymentSteps). Then you can specify in the srProfile this step. Like this: https://github.com/SpecFlowOSS/SpecFlow.Plus.Examples/blob/master/CustomDeploymentSteps/WindowsAppDriver/Default.srprofile#L10 Was this not clear from the example? Please let me know, that I can write it better. – Andreas Willich Jul 17 '20 at 08:38

0 Answers0