none
How do I share testEnvironment information between multiple stepdefinition classes? RRS feed

  • Question

  • I have a test automation code in C# using specflow and selenium. I run the tests on multiple environments. I pass the test environment as a parameter when I execute my test. I have multiple stepdefinition classes and I want to pass the test environment to all the stepdefinition classes. Whats the best way to do this?

     

    Right now, I grab the testEnv information in the Hooks class in a static function getTestConfig() and I call this function in all the stepdefinitions classes( I have multiple stepdefinition classes) . I am unsure if this is a good practice or if it can cause any issues if I want to execute test cases in parallel

    public sealed class Hooks
        {

    private static NameValueCollection testConfig;

     var env = NUnit.Framework.TestContext.Parameters.Get("env");  

        testConfig = ConfigurationManager.GetSection(env) as NameValueCollection;

     public static NameValueCollection getTestConfig()
            {
                return testConfig;
            }

    }

    Friday, October 19, 2018 11:27 PM

All replies

  • Hi Miya2017,

    >>I am unsure if this is a good practice or if it can cause any issues if I want to execute test cases in parallel


    I think that save the config setting into a static method is a good choice. because a static class is loaded by the .NET Framework common language runtime (CLR) when the program that references the class is loaded. 

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 22, 2018 5:23 AM
    Moderator