Reputation: 21
While running the test in selenium Webdriver using JAVA, I do not want the webpage to be seen on the screen. Is there a way that the program runs and the webpage is not seen.
Upvotes: 2
Views: 1830
Reputation: 2938
Yes you can do this like below Use HtmlUnitDriver it opens your web page in headless mode i.e no visibility of any web page for more info about html unit driver please visit
https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.html
also visit http://stackoverflow.com/questions/12807689/selenium-vs-htmlunit
Now back to question
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
Upvotes: 0
Reputation: 42518
If you don't have the budget for a dedicated machine to run tests, then a simple trick is to launch the browser off-screen:
ChromeOptions options = new ChromeOptions();
options.addArguments("--window-position=-32000,-32000");
WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com");
Upvotes: 2