我正在使用MSTest(Visual Studio)单元测试来运行Selenium来测试网站的功能。我想要做的是能够将一些配置变量传递给我的测试。比如,服务器地址,Selenium浏览器类型等等。我一直在尝试使用TestContext,但除了使用LoadTests来传递这些信息外,似乎没有任何其他用途。Visual Studio将配置值传递给UnitTests
我也试过使用Spring.NET,但似乎也没有帮助。
使用TestContext的任何想法?或者也许别的东西。
谢谢
我正在使用MSTest(Visual Studio)单元测试来运行Selenium来测试网站的功能。我想要做的是能够将一些配置变量传递给我的测试。比如,服务器地址,Selenium浏览器类型等等。我一直在尝试使用TestContext,但除了使用LoadTests来传递这些信息外,似乎没有任何其他用途。Visual Studio将配置值传递给UnitTests
我也试过使用Spring.NET,但似乎也没有帮助。
使用TestContext的任何想法?或者也许别的东西。
谢谢
我想我会分享我最终做的。我使用Spring.net将这些设置注入SeleniumSettings类中,
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd" >
<object id="Settings" type="Sample.SeleniumSettings, Sample" singleton="true">
<property name="Server" value="localhost"/>
<property name="Port" value="4444"/>
<property name="Browser" value="*firefox" />
<property name="Url" value="http://website.com"/>
<property name="Email" value="[email protected]"/>
</object>
</objects>
这会将SeleniumSettings注入Test类的一个名为Settings的属性中。测试需要继承AbstractDependencyInjectionSpringContextTests,并执行;
protected override string[] ConfigLocations
设置类看起来像这样;
public class SeleniumSettings
{
public const string DefaultEmailAddress = "[email protected]";
public const string DefaultServerAddress = "localhost";
public const string DefaultProtocol = "http://";
public const string DefaultEndPoint = "/";
public string Server = DefaultServerAddress;
public int Port = 4444;
public string Browser = "*firefox";
public string Url = "http://localhost";
public string Email = DefaultEmailAddress;
public ISelenium factory()
{
return new DefaultSelenium(Server, Port, Browser, Url);
}
}
然后使用SeleniumSettings.factory()来获得DefaultSelenium对象与运行测试。
Selenium文档有这方面的一些信息,但它潜伏得太快,并跳过设置这些东西所需的基本信息。
我试图将DefaultSelenium对象最初注入类中,但是我在Selenium内部崩溃时遇到了问题。它似乎不喜欢被Spring.net注入创建。
我希望这可以帮助别人。