我有一个使用 Selenium 创建的测试方法,类似于:
[TestFixture]
public class Test_Google
{
IWebDriver driver;
[SetUp]
public void Setup()
{
driver = new InternetExplorerDriver();
}
[TearDown]
public void Teardown()
{
driver.Quit();
}
[Test]
public void TestSearchGoogleForTheAutomatedTester()
{
//Navigate to the site
driver.Navigate().GoToUrl("http://www.google.co.uk");
//Find the Element and create an object so we can use it
IWebElement queryBox = driver.FindElement(By.Name("q"));
//Work with the Element that's on the page
queryBox.SendKeys("The Automated Tester");
queryBox.SendKeys(Keys.ArrowDown);
queryBox.Submit();
//Check that the Title is what we are expecting
Assert.True(driver.Title.IndexOf("The Automated Tester") > -1);
}
}
当测试运行时,它会打开一个 IE 并执行它的测试。
想象一下,有 200 种这样的测试方法分布在多个测试夹具中,这意味着 IE 必须多次打开和关闭(与测试夹具一样多,因为每个测试夹具将打开 1 个浏览器)。
如何在不打开浏览器的情况下运行 Selenium 系统测试?
我的意思是,例如,我认为可以开发一个 Windows 服务来在 WinForms Web 浏览器控件中运行 Selenium 测试,在这种情况下,不必每次都打开浏览器,测试可以自动且无缝地运行. 不知道如何实现这一点?
或者还有其他更知名的方式吗?
谢谢,