如何在不需要打开浏览器的情况下运行Selenium系统测试?

The*_*ght 3 testing selenium windows-services webbrowser-control system-testing

我有一个使用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);
    }
}
Run Code Online (Sandbox Code Playgroud)

测试运行时,会打开IE并执行测试.

想象一下,有200种这样的测试方法分布在多个测试夹具上,这意味着IE必须多次打开和关闭(与测试夹具一样多,因为每个测试夹具将打开1个浏览器).

如何在不需要打开浏览器的情况下运行Selenium系统测试?

我的意思是,例如我认为可以开发一个Windows服务来运行WinForms Web浏览器控件中的Selenium测试,在这种情况下,浏览器不必每次都打开,测试可以自动且无缝地运行.不知道怎么实现这个呢?

或者还有其他更为人熟知的方式吗?

谢谢,

Pri*_*kar 5

不,Selenium是用JavaScript编写的; 它被设计为在真实的浏览器中运行,以测试与真实浏览器的兼容性.有许多其他工具可用于运行模拟浏览器的测试; 你可以查看HtmlUnitCanoo WebTest.

希望这会帮助你.