1
votes

I'd like to write one suite of SpecFlow tests that test my web application (using Selenium) in various environments.

so I have a test written like this

Given that I am on the login page

which in turn leads to a step definition that boils down to

driver.Navigate().GoToUrl("http://www.myapp.com/login.aspx");

However, I want my test to be able to run against "http://localhost" or `"http://test.myapp.com" as well, without having to recompile. The best idea I've come up with is to place these sorts of settings in the App.config file, but that has its problems as well.

Does anyone have suggestions on how best to achieve this? Basically I want to pass in environment settings for my tests at runtime.

2
Are you looking for the user to specify that when they are running the test or some sort of parameter from an external runner?Dan Snell
I would like to pass in the parameter from an external runner. Basically "Execute these tests against my local environment" or "Execute these tests against the test/QA environment". Ideally the tests would be automated to run against a deployment with each new build.Greg Ferreri

2 Answers

0
votes

I would still question whether you might be better and starting a local instance of the service that you wish to test, rather than connecting to something which is out of the tests explicit control. You could instead use a method similar to self hosting a web api or host a wcf service to do this for you. This way you can inject mocks, modify and reset the database, or perform any other action you want.

If that still isn't what you need, an alternative to config files would be to setup environment variables that can be read at run time, see How to pass Command line argument to specflow test scenario

0
votes

You can do this by changing the config file through the build process using transforms and there are tools that will let you run the transform outwith the build process (so you don't have to manually change it and you avoid a build) using the command line. This has been talked about already on SO: Web.Config transforms outside of Microsoft MSBuild?

For example using PowerShell.