2

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.

 [AssemblyInitialize]
        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);
            Driver.Navigate().GoToUrl(item);
            Driver.Manage().Window.Maximize();

            SetupElm elm = new SetupElm();
            elm.IdentityServer.Click();


            Extent = new ExtentReports(ExtentHTMLReportPath, true);


            }
4
  • Try virtual environment, it will work. Each virtual environment handles one instance of browser to test one particular environment under test.
    – Yu Zhang
    Feb 5, 2017 at 11:43
  • You mean something like virtual machine ,VM ware ...etc
    – ChathuD
    Feb 5, 2017 at 12:10
  • yes, exactly what i meant
    – Yu Zhang
    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
    Mar 7, 2017 at 15:21

1 Answer 1

2

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

Java

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

Example

Instead of this:

WebDriver driver = new ChromeDriver(...);
driver.get("http://dev/app/...");

Use this:

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

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/...

.NET

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

Example

Instead of this:

var driver = new ChromeDriver(...);
driver.Navigate().GoToUrl("http://dev/app/...");

Use this:

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

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.

1
  • 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
    Feb 5, 2017 at 9:21

Your Answer

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

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