
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
Advertisements