简体   繁体   中英

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 tests in C#. Is there a way to specify at runtime the URL and the Browser without having to change the code and rebuild?

Basically can I run the same tests against different URLs (Dev, QA , UAT etc) and different Browsers without having to recomplile.

Many Thanks.

After much searching I eventually came up with the solution by combining the best bits of two other incomplete solutions.

Config file should be the same name as your test file dll eg TestFile.dll.config and located in the same folder.

This is the format of your config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <startup>
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
   </startup>
   <appSettings>
     <add key="TestURL" value="http://www.example.com/"/>
     <add key="Browser" value="Firefox"/>
   </appSettings>
 </configuration>

Add a reference and a using statement for System.Configuration and use code like this to access your parameters:

 testURL = ConfigurationManager.AppSettings["TestURL"];
 browser = ConfigurationManager.AppSettings["Browser"];

All improvements, suggestions and comments are welcome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM