On my project i have 4 different environment. Dev,stag,uat and prod. So i need to run a test case for all four environments as a one test case.

Only the change to the code will be web driver URL.

So below is my AssemblyInitialize and in here im trying open the webdriver with two of my environments. but it is not going to work.

        public static void setupDriver(TestContext TestContext)
            string[] array = new string[2];
            array[0] = URL1;
            array[1] = URL2;
            foreach (var item in array)

            Driver = new ChromeDriver(ChromeDriverFilePath);

            SetupElm elm = new SetupElm();

            Extent = new ExtentReports(ExtentHTMLReportPath, true);

  • Try virtual environment, it will work. Each virtual environment handles one instance of browser to test one particular environment under test.
    – Yu Zhang
    Commented Feb 5, 2017 at 11:43
  • You mean something like virtual machine ,VM ware ...etc
    – ChathuD
    Commented Feb 5, 2017 at 12:10
  • yes, exactly what i meant
    – Yu Zhang
    Commented Feb 5, 2017 at 12:14
  • Do the different environments differ wildly in configuration? I imagine you should be able to use variables for all the server-specific configuration and then fill these variables at runtime?
    – Cronax
    Commented Mar 7, 2017 at 15:21

1 Answer 1


As always, there's numerous ways to do this. Here are just two example:


If you use Java, you can use System Properties to pass configuration data like the target URL into your test.


Instead of this:

WebDriver driver = new ChromeDriver(...);

Use this:

String env = System.getProperty("target.env");
WebDriver driver = new ChromeDriver(...);

This allows you to specify a value for target.env dynamicaly at runtime.

How you specify the value when executing tests depends on how you run them. If you start your tests from Eclipse, see this question for example.

If you run your tests through the command line, just add the -D switch and specify the value accordingly:

java -jar mytests.jar -Dtarget.env=http://prod/app/...


In .NET the simplest way to do this is passing that information via an environment variable.


Instead of this:

var driver = new ChromeDriver(...);

Use this:

var env = Environment.GetEnvironmentVariable("targetenv");
var driver = new ChromeDriver(...);

When running the tests, just make sure that you set the environment variable targetenv to the desired URL. You can easily do this in the command line, as described here.

  • Thanks for the detailed description , But i think i didnt get the exact answer im looking for so that i will update my question.
    – ChathuD
    Commented Feb 5, 2017 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.