selenium - How can I specify a different URL and/or Browser to run my C# WebDriver test against at runtime? -
I am using WebDriver and NUnit to create a test in C #. Is there any way to specify URLs and browsers without changing the code on the runtime and rebuilding?
Actually, I can run against different URLs (Dev, QA, UAT etc) and different browsers without having to repeat the same test again.
Many thanks.
After more searching, I finally came from the solution, combining two best bits of other incomplete solutions
The config file should be the same name as your test file DLL TestFile.dll.config and located in the same folder.
This is the format of your config file:
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Configuration & gt; & Lt; Startup & gt; & Lt; Supported serial version = "v4.0" sku = ".NETFramework, version = v4.5" /> & Lt; / Startup & gt; & Lt; AppSettings & gt; & Lt; Add key = "TestURL" value = "http://www.example.com/" /> & Lt; Add Key = "Browser" value = "Firefox" /> & Lt; / AppSettings & gt; & Lt; / Configuration & gt; Add a reference and an experiment statement for System.Configuration and use the code to access your parameters like this:
testURL = ConfigManager .AppSettings ["TestURL"]; Browser = Configuration Manager App settings ["browser"]; All improvements, suggestions and comments are welcome.
Comments
Post a Comment