我想要简单的方法来启动Selenium webdriver实例并在其上运行各种测试。我试图在Suite文件中这样做,但它不起作用。实例立即死亡。有没有其他方法可以做到这一点?如何在NUnit和C#中共享一个Selenium webdriver实例?
可能我想在此套件中添加更多驱动程序(IE,Chrome),如果可能的话单独启动。欢迎任何建议。
namespace NUnit.Tests
{
public class AllTests
{
private static IWebDriver _Driver;
[TestFixtureSetUp]
public void SuiteSetUp()
{
_Driver = new FirefoxDriver();
}
[TestFixtureTearDown]
public void SuiteTearDown()
{
try
{
_Driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
}
[Suite]
public static TestSuite Suite
{
get
{
LoginTest lt = new LoginTest { Driver=_Driver };
suite.Add(lt);
AnotherTest at = new AnotherTest { Driver=_Driver };
suite.Add(at);
return suite;
}
}
}
}
我会尽力的。在这种情况下,如何启动不同的浏览器并行? – Gita 2012-01-03 15:58:10
我使用了TestNG,然后使用它的参数化变量功能来运行各种浏览器。 它也有一个并行执行选项。 对不起,但我不熟悉NUnit。 – MostWanted 2012-01-03 16:11:48
使用基类和扩展类尝试此操作后,它不起作用。所以我在Suite中创建了单独的测试来设置和拆卸浏览器。将这些作为第一个/最后一个添加到套件中,并且它像魔术一样工作感谢您的意见。 – Gita 2012-03-12 14:58:21