How to open multiple Chrome browser tabs using Incognito

Copy the following into any new test case and execute.

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()

5 Likes

Hi @Dave_Evers ,

Thank you so much for sharing this tip. We appreciate your contribution