我使用Selenium創建了一個測試方法,類似於這樣:如何在不需要打開瀏覽器的情況下運行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測試,在這種情況下,瀏覽器不必每次都打開,測試可以自動無縫運行。不知道如何實現這個呢?
或者還有其他更好的方法嗎?
謝謝,
取決於你如何運行它。你可以使用HtmlUnitDriver,如果沒有GUI,你就沒問題,但是當只有真正的瀏覽器計數時,你必須使用假的X或VNC或類似的東西。 – ReneS