簡體   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