Testing in Chrome’s Incognito mode in Selenium WebDriver. Below is the detailed tutorial and step-by-step guide to run the test execution in Chrome’s Incognito mode using Selenium with Java.
Incognito mode allows users to browse the web without saving any browsing history and cookies
In Incognito/Private mode, the browser creates a separate session that is isolated from the main browser session and user data, which is temporary and not saved.
Example:
package TestAutomationCentral; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class IncognitoMode { public static void main(String[] args) { //TestAutomationCentral.com System.setProperty("webdriver.chrome.driver", "C:\\temp\\drivers\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--incognito"); WebDriver driver = new ChromeDriver(options); driver.get("https://www.google.com/"); System.out.println(driver.getTitle()); } }
In this example, we have passed “–incognito” for ChromeOptions arguments and passed the ChromeOptions in ChromeDriver class.