Hello Katalon Team, i am currently doing a test scenarios for a proof of concept and however being blocked. Below is my scenario:
The typical scenario requires the tester (using always the same identity) to handle THREE browsers simultaneously:
- access an App in Browser1 , get redirected to an app for authentication, get a session, get access
- access an App in Browser2 , get redirected to an app for authentication, get a session, get access
- in Browser1 , observe that access to another app is transparent, no re-authentication is required
- access an app in Browser3 , get redirected to an application for authentication, get a session, get access
- in Browser2 , observe that access to another app is transparent, no re-authentication is required
- in Browser1 , observe that the session is gone, i.e., that the identity is redirected for re-authentication.
@kazurayam, could you please help how to overcome that issue? I checked on the forum but could not get a solution for the above typical scenario.
Thanks in advance.
I am sorry, I do not understand your description above. You described something, but have not made any question.
What is “that issue”?
Have you been successful for the step#1?
Have you been successful for the step#2?
Have you been successful for the step#3?
Have you been successful for the step#4?
Have you been successful for the step#5?
Have you been successful for the step#6?
…
I don’t see.
The issue is that, after opening browser 1 and browser 2, im not able to switch to browser 1 to perform a test. Then switch to browser 2 to perform another test. That switching is my issue 
Please show your test case script.
Every detail is hidden in your custom keywords. I can not help you debugging your custom keywords.
Essentially you are doing this:
WebUI.openBrowser(null) // browser1
WebUI.openBrowser(null) // browser2
Yes, you would see 2 browser windows opened.
But, you will loose the 1st session from Katalon to the browser1 as soon as the 2nd session started.
is there a solution, to switch back to the first session?
You should not use WebUI.openBrowser()
at all. It maintains only 1 session from Katalon process to browser.
You should create multiple WebDriver instances (ChromeDrvier, FirefoxDriver) yourself. You want to create 2 instances and keep them alive. Use DriverFactoy.changeWebDriver()
method to switch the target of WebUI.* keywords to the browser1, to the browser2, and back to the browser1, …
The following code works for me.
import org.openqa.selenium.WebDriver
import com.kazurayam.ks.webdriverfactory.WebDriverFactory
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
// open browser1, keep the session to the browser1 alive
//WebDriver browser1 = WebDriverFactory.newWebDriver(DriverFactory.getExecutedBrowser(), 'Katalon') // open browser with profile 'Katalon'
WebDriver browser1 = WebDriverFactory.newWebDriver(DriverFactory.getExecutedBrowser())
assert browser1 != null
// open browser2, keep the session to the browser2 alive
WebDriver browser2 = WebDriverFactory.newWebDriver(DriverFactory.getExecutedBrowser())
assert browser2 != null
// in browser1, navigate to a URL
DriverFactory.changeWebDriver(browser1)
WebUI.navigateToUrl('http://demoaut.katalon.com/')
// in browser2, navigate to a URL
DriverFactory.changeWebDriver(browser2)
WebUI.navigateToUrl('https://duckduckgo.com/about')
// switch to browser1 and do something
DriverFactory.changeWebDriver(browser1)
String title1 = WebUI.getWindowTitle()
WebUI.comment("title1: ${title1}")
// switch to browser2 and do something
DriverFactory.changeWebDriver(browser2)
String title2 = WebUI.getWindowTitle()
WebUI.comment("title2: ${title2}")
WebUI.delay(3)
browser2.quit()
browser1.quit()
You can create ChromeDriver yourself using org.openqa.selenium.webdriver.chrome.*
API. This API is bundled in Katalon Studio and available for test cases. See https://chromedriver.chromium.org/getting-started
In the above sample, I use com.kazurayam.ks.webdriverfactory.WebDriverFactory
. It is my custom Groovy class. Have a look at its README. This enables me creating WebDriver instance with custom Chrome Profile (e.g, Katalon
). The jar (ver 0.3.0) of this class is available at https://github.com/kazurayam/WebDriverFactory4ks/releases. You want to download the jar and locate it into the Drivers
folder of your katalon project. To be honest, the doc of webdriverfactory
project is not well written; I know the doc has some mistakes. I have already lost my interest in it.
1 Like
Hello @kazurayam, thank you. Have a nice weekend & stay safe.