How does one open 1 normal chrome browser and 1 incognito chrome browser?

Hi all

So I was wondering how one opens 1 instance of a normal chrome browser and 1 instance of incognito chrome browser.

This link supposedly figured it out, and when I copied the script to Katalon, it indeed opened two instances of chrome, and worked on them simultaneously, however the one was sadly not incognito.

I am assuming that this is supported now, as it was possible, and that it is possible to have two instances of chrome browsers open and switch back and forth between them. But to do my software testing I need to be able to use an incognito mode so that my sessions don’t get mixed up

PLEASE NOTE: I know that one can in the preferences set chrome to open in incognito, however I specifically need 1 instance to be normal chrome and 1 instance to be incognito

The topic you linked has the correct idea, you just need to add the --incognito argument to the driver instance that you want to be incognito. I think this is what’s intended in that post, they just don’t show the implementation (at least I couldn’t find it easily). I’m talking about this part:

WebDriver incognitoChrome = openChromeBrowserInIncognitoMode()

(openChromeBrowserInIncognitoMode() is not shown) Here’s how to do it yourself:

ChromeOptions options = new ChromeOptions()
options.addArgument('--incognito')
WebDriver incognitoChrome = new ChromeDriver(options)

Here’s the full example, with the above replaced:

// open 2 Chrome browser, one in normal mode on the left, another in incognito mode on the right
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()

@kazurayam I found a small issue in your code that’s causing this to not work as intended for OP. In your openChromeBrowserInIncognitoMode() method, when you add the incognito argument, you need 2 dashes. Here’s your current code snippet:

ChromeDriver openChromeBrowserInIncognitoMode() {
	ChromeOptions options = new ChromeOptions()
	options.addArguments("-incognito")
	return openChromeBrowser(options);
}

It needs to be:

ChromeDriver openChromeBrowserInIncognitoMode() {
	ChromeOptions options = new ChromeOptions()
	options.addArguments("--incognito")
	return openChromeBrowser(options);
}

Thank you for this. It works now.

However for some reason I am having trouble that some of my objects don’t want to work at all, and I don’t know why.

Is there any easier way to do this? Like a simpler way?

Not really, no. You could simplify a few things, namely you can put this in a keyword, then you wouldn’t need to do this in every script. Another idea would be to have two separate scripts that each use a different browser (normal/incognito) and run them in parallel, but I don’t know if that fits your use case.

Do you have an example of this that we can look at?

When I have a normal instance of chrome open, using WebUI.openBrowser(), I can use the following script to set the text:

// Sets the OTP from the Noted Feedback as a variable "OTP"
OTP = WebUI.getText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/span_6031'))

// On the modal, enters the OTP by pasting the OTP variable that it stored
WebUI.setText(findTestObject('Enrolment/Page_Connect - Operations - Student Enrolment/input_Please check your junk mail folder if_d47c1f'), 
    OTP)

Where the xpath of the set text test object is //input[@id=‘VerificationOTP’]

However, if I have a normal instance of chrome open using the following method, then this doesn’t work:

// open normal Chrome browser on the left side
WebDriver normalChrome = openChromeBrowserPlain()

resizeHorizontalHalfLocateLeft(normalChrome)

DriverFactory.changeWebDriver(normalChrome)

WebUI.navigateToUrl('www.google.com')

WebUI.waitForPageLoad(10)

// open incognito Chrome browser on the right side
ChromeOptions options = new ChromeOptions()

options.addArguments('--incognito')

WebDriver incognitoChrome = new ChromeDriver(options)

resizeHorizontalHalfLocateRight(incognitoChrome)

DriverFactory.changeWebDriver(incognitoChrome)

WebUI.navigateToUrl('www.youtube.com')

WebUI.waitForPageLoad(10)

This is the example of the Test Object that doesn’t work

What we really need is the error you are getting.

Nevermind, I see your other topic: Element Not Interactable in a certain test case

Marking a solution and closing this topic.

1 Like