如果你还想看这三个都是 VS 测试视图,你可以试试这个。(但是如果你有十个不同的浏览器呢?)
[TestMethod]
public void LoginTestFF() {
ExecuteLoginTest();
}
[TestMethod]
public void LoginTestIE() {
ExecuteLoginTest();
}
[TestMethod]
public void LoginTestChrome() {
ExecuteLoginTest();
}
public void ExecuteLoginTest() {
//real test steps
}
如果您只想为所有浏览器重用代码,您可以在 App.config 中定义您想要的浏览器,然后使用 switch case 进行选择。
<add key="Browser" value="Chrome"/>
IWebDriver driver;
string browser = ConfigurationManager.AppSettings["Browser"];
switch (browser) {
case "Firefox":
driver = new FirefoxDriver();
break;
case "IE":
driver = new InterntExplorerDriver();
break;
case "Chrome":
driver = new ChromeDriver();
break;
default:
break;
}
// if this test can only be run against FF and Chrome, add test category to it
[TestMethod, TestCategory("Firefox"), TestCategory("Chrome")]
public void LoginTestTest() {
//real test steps
}