How to run a parameterized Selenium test with NUnit on TeamCity?

I am writing Selenium webdriver tests in Visual Studio, using C#. These are basically regression tests. The framework that I have chosen in NUnit.

I want to parameterize the URL, so the same tests can be run against different deployments in TeamCity. How do I do that? Should I create a Console Application and then pass an argument to Main()? In that case how do I run the tests from NUnit GUI?

Is any other Framework better than NUnit?

Thanks!

Upvotes: 1

Views: 2246

Answers (2)

Eelke
Eelke

Reputation: 21

We start with a default App.config with values set for running tests locally, for development. Then we have TeamCity swap out the App.config, in a build step, with other config files for different builds. That's how you can have different settings for different builds, such as target URL.

Upvotes: 0

nologo
nologo

Reputation: 6328

hey here are some useful links which might help answering your question:

http://codewandering.blogspot.com.au/2008/11/regression-testing-for-any-web.html

http://kristjansson.us/?p=947

Additionally you can use environment variables configured in teamcity against the build (so in nightly you might have a different url from a dev build etc) and call the variable in your source code:

public static string GetBaseUrl()
{
    return string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("testurl")) ? ConfigurationManager.AppSettings["baseurl"] : System.Environment.GetEnvironmentVariable("testurl");
}

in the code sniplet above, I check to see if i've got the environment and if not, use the appconfig as a backup.

within TeamCity, you set the variables under each configuration:

Edit Config > Build Params > add Environment Variables > select Environment Variables as Kind (env.testurl in my example). note, when calling this value within C# i don't include the env. section from the TeamCity variable name.

Upvotes: 1

Related Questions