如何运行Selenium系统测试,无需打开浏览器?
-
14-11-2019 - |
题
我有一个使用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个测试方法,如这种测试方法,跨多个测试夹具蔓延,这意味着必须多次打开并关闭(由于1浏览器的测试夹具,每个测试夹具都会打开)。
如何运行Selenium系统测试,而无需打开浏览器?
我的意思是我认为可以在Winforms Web浏览器控件中开发一个Windows服务来运行Selenium测试,在这种情况下,每次都必须打开浏览器并运行测试自动无视。不确定如何实现这一点吗?
或有其他更好的已知方式吗?
谢谢,
解决方案
no。Selenium是用JavaScript编写的;它旨在在真正的浏览器中运行,以测试与实际浏览器的兼容性。有各种其他工具,设计用于运行模拟浏览器的测试;您可以调查 htmlunit 或 canoo webtest 。
希望这将为您提供帮助。
其他提示
你试过xlt吗? 它根本不需要开放式浏览器 http://www.xceptance.com/products/xlt/what-is-xlt.html
如果您愿意,您可以在一个浏览器实例中运行所有测试。您只需将WebDriver实例传递给每个测试。喜欢在静态类中拥有Singelton webdriver,从所有测试程序都可以访问webdriver。罚款罚款,如果您有会话以保持
驱动程序=新的htmlunitdriver(true); java.util.logging.logger.getLogger(“com.gargoyleSoftware”)。setLevel(level.off);
不隶属于 StackOverflow