繁体   English   中英

测试时在 selenium webdriver 中隐藏网页

[英]hide the webpage in selenium webdriver while testing

在使用 JAVA 在 selenium Webdriver 中运行测试时,我不希望在屏幕上看到网页。 有没有办法让程序运行而看不到网页。

如果您没有专门的机器来运行测试的预算,那么一个简单的技巧是在屏幕外启动浏览器:

ChromeOptions options = new ChromeOptions();
options.addArguments("--window-position=-32000,-32000");

WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com");

是的,您可以像下面那样使用 HtmlUnitDriver 它以无头模式打开您的网页,即没有任何网页的可见性有关 html 单元驱动程序的更多信息,请访问

https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.html

visit http://stackoverflow.com/questions/12807689/selenium-vs-htmlunit

现在回到问题

WebDriver driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// do some action with html unit driver
// for example open google home page
driver.get("http://www.google.com");
// now verify that google home page is loaded properly
System.out.println("Printing Title of the Google Home Page : " + driver.getTitle());

// above line prints on console : Printing Title of the Google Home Page : Google

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM