How to open a private (incognito) & a public chrome browser tab

The following can be used as an example of how to work with two chrome browser tabs where one tab is using incognito and the other tab is using a regular chrome tab. This solution was originally posted here: Incognito Window Chrome - #9 by josh.meeks A few edits were made to the post to make it work as expected. Copy and paste the following into a new test case and run it…

import org.openqa.selenium.WebDriver as WebDriver 
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.Dimension
import org.openqa.selenium.Point
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

//Open the first window (regular Chrome)
WebUI.openBrowser('https://www.google.com')
WebDriver regularChromeDriver = DriverFactory.getWebDriver()
// Adjust width and height as needed
Dimension regularChromeWindowSize = new Dimension(970, 1100)
// Adjust x and y coordinates as needed
Point regularChromeWindowPosition = new Point(0, 0)
regularChromeDriver.manage().window().setSize(regularChromeWindowSize)
regularChromeDriver.manage().window().setPosition(regularChromeWindowPosition)
//Store the original window handle
String originalWindowHandle = regularChromeDriver.getWindowHandle()

//Open the second window (Incognito mode)
ChromeOptions options = new ChromeOptions()
options.addArguments('--incognito')
WebDriver incognitoDriver = new ChromeDriver(options)
incognitoDriver.get('https://www.google.com')
// Adjust width and height as needed
Dimension incognitoWindowSize = new Dimension(970, 1100)
// Adjust x and y coordinates as needed
Point incognitoWindowPosition = new Point(955, 0)
incognitoDriver.manage().window().setSize(incognitoWindowSize)
incognitoDriver.manage().window().setPosition(incognitoWindowPosition)

//Switch to the Incognito window
DriverFactory.changeWebDriver(incognitoDriver)
//Perform actions in the Incognito window (e.g., enter data)
WebUI.delay(5)

//Switch back to the regular Chrome window
DriverFactory.changeWebDriver(regularChromeDriver)
//Perform actions in the regular Chrome window and observe data update
WebUI.delay(5)

//Close the windows
regularChromeDriver.quit()
incognitoDriver.quit()

4 Likes