I for the life of me cant seem to get any of the posted “Solutions” to work to open an Incognito Chrome Tab. Can anyone walk me through setting this up? `WebDriver normalChrome = openChromeBrowserPlain()
resizeHorizontalHalfLocateLeft(normalChrome)
DriverFactory.changeWebDriver(normalChrome)
WebUI.navigateToUrl(‘http://demoaut.katalon.com/’)
WebUI.waitForPageLoad(10)
ChromeOptions options = new ChromeOptions()
options.addArgument(‘–incognito’)
WebDriver incognitoChrome = new ChromeDriver(options)
resizeHorizontalHalfLocateRight(incognitoChrome)
DriverFactory.changeWebDriver(incognitoChrome)
WebUI.navigateToUrl(‘http://demoaut-mimic.kazurayam.com/’)
WebUI.waitForPageLoad(10)
// in the normal Chrome, do something
DriverFactory.changeWebDriver(normalChrome)
WebUI.comment(“switched to ${WebUI.getUrl()}”)
WebUI.verifyElementPresent(button, 10, FailureHandling.STOP_ON_FAILURE)
WebUI.click(button)
WebUI.delay(1)
// in the incoginto Chrome, do something
DriverFactory.changeWebDriver(incognitoChrome)
WebUI.comment(“switched to ${WebUI.getUrl()}”)
WebUI.navigateToUrl(‘http://demoaut-mimic.kazurayam.com/’)
WebUI.click(button)
WebUI.delay(1)
// close 2 browser windows
DriverFactory.changeWebDriver(normalChrome)
WebUI.closeBrowser()
WebUI.delay(1)
DriverFactory.changeWebDriver(incognitoChrome)
WebUI.closeBrowser()`
1 Like
Hi @josh.meeks, This works for me…
Copy and paste the following into a new test case and run it…
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration
//testCase body
RunConfiguration.setWebDriverPreferencesProperty('args', ['--incognito'])
WebUI.openBrowser('https://www.bbc.com/news/world')
WebUI.executeJavaScript('window.open();', null)
currentWindow = WebUI.getWindowIndex()
//Navigate to 2nd tab
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.navigateToUrl('https://www.google.com')
WebUI.delay(5)
//Navigate to 1st tab
WebUI.switchToWindowIndex(currentWindow)
Katalon Studio Version:
Enterprise | Version 8.6.8
Windows 11 Enterprise (64-bit)
Chrome Version Version 119.0.6045.160 (Official Build) (32-bit)
Hi @Elly_Tran,
I set my Chrome browser to use ‘–incognito’ (which works as expected), as per this link:
I also followed these instructions but KSE ‘Web Record’ is not working/won’t capture any elements, any suggestions? Not surprised it does not work as I don’t believe KSE uses the browser extension? Or does it?
Open Incognito window
Go to chrome://extensions
Find the Katalon Studio extension, click Details
Toggle the button Allow in Incognito
Hi,
I will ask my team for a workaround and back to you soon/
1 Like
That works great thank you! However I believe i did not explain what exactly I was looking to do correctly. I would like to open a normal session of chrome, then open a second window in incognito mode, and switch between the two.
Hi @josh.meeks, You could try invoking incognito in only the 2nd tab. Not sure if that would work… Give it a try.
Thanks for the thought but yeah I tried that soon as I saw your first reply. Doesnt seem to work. Not sure how do handle having to perform a test where its live updating in the normal chrome window based on inputs received from an Incognito window.
Hi @Dave_Evers , I think I got it all figured out. This seems to be exactly what I was looking for.
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()
Dimension regularChromeWindowSize = new Dimension(970, 1100) // Adjust width and height as needed
Point regularChromeWindowPosition = new Point(0, 0) // Adjust x and y coordinates as needed
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")
Dimension incognitoWindowSize = new Dimension(970, 1100) // Adjust width and height as needed
Point incognitoWindowPosition = new Point(955, 0) // Adjust x and y coordinates as needed
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)
// Switch back to the regular Chrome window
DriverFactory.changeWebDriver(regularChromeDriver)
// Perform actions in the regular Chrome window and observe data update
// Close the windows
regularChromeDriver.quit()
incognitoDriver.quit()
Please share this out if there are those needing some help with this. This works like a charm.
2 Likes
@josh.meeks I notice that you have 1 backtick in your post, but when you post lines of code, you need 3 backticks on a line by themselves, like you have the single one at the end. (The one backtick at the top needs to become 3 and put on a line by themselves.)
Use 1 backtick when you want to keep formatting on a single line, or using pathway formatting to keep the back slashes correct, like //input[@id="login"]
, or tag formatting, like <select>
.
@grylion54 , I just assumed that </> was for posting lines.
Hi @josh.meeks I had to add “import org.openqa.selenium.WebDriver as WebDriver
” to your imports to make this work. Great work figuring this out… Other folks may be able to make use of this solution so I am adding it as a tip under the Katalon Studio tips category.
import org.openqa.selenium.WebDriver as WebDriver //Had to add this import
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()
1 Like
Hi @Elly_Tran, Have you heard anything from your team?
Thanks Dave