- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Selenium testing without browser.
We can perform Selenium testing without a browser. This is achieved by triggering the execution in a headless mode. The headless execution can decrease the utilization of key resources and is being adopted widely.
For triggering headless execution in Chrome, the ChromeOptions class is utilized to modify the default browser characteristics. Headless is passed as a parameter to the addArguments.
Syntax
ChromeOptions opt = new ChromeOptions(); opt.addArguments("headless"); WebDriver d = new ChromeDriver(opt);
Example
Code Implementation.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import java.util.concurrent.TimeUnit; public class WithoutBrowsr{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); //ChromeOptions object ChromeOptions opt = new ChromeOptions(); //headless parameter opt.addArguments("headless"); // set parameter to Chrome driver WebDriver driver = new ChromeDriver(opt); driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS); driver.get("https://www.tutorialspoint.com/questions/index.php"); // obtain page title System.out.println("Page title without browser: " + driver.getTitle()); driver.quit(); } }
Output
- Related Articles
- Browser Plugin Testing With Selenium.
- Does Selenium support headless browser testing?
- How to close active/current tab without closing the browser in Selenium-Python?
- Python selenium browser driver.back().
- Best Cross Browser Compatibility Testing Tools
- Use Selenium with Chromium Browser.
- Does Selenium support Safari browser?
- Handling Browser Authentication using Selenium
- 20 Best Cross Browser Compatibility Testing Tools
- How to perform browser navigations in Selenium?
- Get PID of Browser launched by Selenium.
- How to start selenium browser with proxy?
- How to launch Chrome Browser via Selenium?
- How to maximize the browser in Selenium?
- How to do UI testing with Selenium?

Advertisements