How can I set up a class library containing browser-based integration tests to have different configuration options based on the build configuration / environment combo?
I have a test class library in .NET that has a mix of unit tests, integration tests, and some new acceptance style Selenium tests. In the past for a web project I have done config file replacement so I can specify a different set of configuration values for different build configurations (Dev
/ Stage
/ Release
, etc...). I also know that I can store settings used by the test library int the App.config
file so I assume something like this is possible for a class library as well but have not been able to find any answers.
For example, when I run the Selenium acceptance tests on my local development machine, I have a specific localhost URL for the website Selenium is being run against (and I run a Debug
build), but this URL differs in my dev (and other environments).
How can I achieve this?
I have done some research on this, but nothing specifically answered this question. Many of the other answers I've found have to do with unit testing the config file (Unit testing the app.config file with NUnit) or modifying the config file at runtime, which is not what I want. The only one that came close was this question here: How do I run my NUnit test cases using Selenium to run against different environments? but the answer given is a lot of custom code, that would need to be maintained if new build configurations or environments are added which is not what I want. I would like (if possible) a configuration file replacement solution so this scales and can be run by me on my machine, by a QA who doesn't have studio, or by a CI server like TeamCity as part of a post-build process. In addition, a config file replacement will also keep the test library consistent with the way the rest of the code base is set up.
It is important to note that I don't necessarily want to store values needed by the code I'm testing because these are browser-based acceptance tests. I am merely concerned with storing values that control the execution of my test suite and affect how my tests interact with the site (not performing operations that would modify a production database when running the tests on live for example).
Here is a code snippet to help illustrate how this would be used:
Private _baseUrl As String
Private _driver As IWebDriver
<Setup()> _
Protected Overridable Sub Setup()
'This config call will return a different value based on the project build (Dev / Stage / Live)
_baseUrl = ConfigurationManager.AppSettings("BaseWebUrl")
Dim options As New IE.InternetExplorerOptions()
options.IgnoreZoomLevel = True
_driver = New IE.InternetExplorerDriver("PathToIEExecutable", options)
End Sub
<TearDown()> _
Protected Overridable Sub TearDown()
_driver.Quit()
End Sub
<Test(), Category("Acceptance")> _
Public Sub HomePage_NewUserVisit_ShouldSeeWelcomeMessage()
Me.Driver.Navigate().GoToUrl(_baseUrl)
Me.Driver.VerifyElementPresent("//body/div[@id='welcome-message']")
Assert.AreEqual("This Website R0xor3s - Welcome", Me.Driver.Title, "Unexpected Title.")
End Sub
Protected ReadOnly Property Driver As IWebDriver
Get
Return _webDriver
End Get
End Property
I am using NUnit (2.6.3) and Selenium WebDrivers (2.4.1)