Problem to solve
- In a single Katalon Test Case, I want to open 2 windows of Chrome Browser. One in normal mode, another in Incognito mode.
- I want to perform various testing actions on each browser window using
WebUI.*
keywords as usual. - I want to repeat switching between 2 windows back and forth.
Why Incognito mode
Quote from https://www.metacompliance.com/blog/3-reasons-to-browse-the-internet-in-incognito-mode/
- Multiple sessions – One of the great advantages of going Incognito, is it enables you to sign in to multiple accounts simultaneously. For example, you could log into your work account from an Incognito window whilst remaining in your personal account from a normal window. Similarly, if you had a friend over that wanted to log into their social media account, they could do this in a separate incognito window so you wouldn’t have to log out of your own account.
Driving multiple sessions introduces a new perspective into Web UI testing. You can open 2 browser windows in incognito mode, sign in to your web service using 2 different accounts respectively. You want to navigate to a single page on each windows. Then you can look at a web page on 2 windows simultaneously and somehow compare them.
Solution
com.kms.katalon.core.webui.driver.DriverFactory#changeWebDriver(org.openqa.selenium.WebDriver)
does the magic.
Demo video
Here is a demo video:
Description
I have made a code and published it on GitHub at WebDriverFactory4ks/Test Cases/main/miscellaneous/open2ChromeBrowsersAndTestBothSimultaniously
The core portion is as follows:
TestObject button = new TestObject().addProperty('css', ConditionType.EQUALS, '#btn-make-appointment')
// 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)
WebDriver incognitoChrome = openChromeBrowserInIncognitoMode()
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()
I used Katalon Studio v7.7.2 on Mac OS Big Sur 11.0.2.