How to Test Two Browsers using WebDriver

Hi Russ_Thomas,

I think that @Hariprasad1 was referring to two browsera.
Anyway, I have the same problems when I have to switch from one browser to another.

Following my script into TestCase:

System.setProperty(‘webdriver.chrome.driver’, DriverFactory.getChromeDriverPath())
WebDriver driver1 = new ChromeDriver()
WebDriver driver2 = new ChromeDriver()

// first browser
DriverFactory.changeWebDriver(driver1)
WebUI.openBrowser(’’)
WebUI.navigateToUrl(‘MY HTTPS A’)
//some action

// second browser
DriverFactory.changeWebDriver(driver2)
WebUI.openBrowser(’’)
WebUI.navigateToUrl(‘MY HTTPS B’)
//some action

//I need come back into first browser.How can I do?
//some action
//I nedd come backe into secondo browser. How can I do?

Thanks
AndyCapp

Try this code:

import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

System.setProperty("webdriver.chrome.driver", 
  DriverFactory.getChromeDriverPath())

WebDriver driver1 = new ChromeDriver()
WebDriver driver2 = new ChromeDriver()

// first browser
DriverFactory.changeWebDriver(driver1)
WebUI.navigateToUrl("https://www.duckduckgo.com")

// second browser
DriverFactory.changeWebDriver(driver2)
WebUI.navigateToUrl("https://www.google.com")

// first browser
DriverFactory.changeWebDriver(driver1)
WebUI.maximizeWindow()

// second browser, navigate from duckduckgo to Katalon
DriverFactory.changeWebDriver(driver2)
WebUI.navigateToUrl("https://katalon.com")

Tested in Katalon Studio 7.9.0rc

p.s. Andy Cap :rofl:

He wouldn’t get far in today’s “pc” environment :wink:

1 Like

Similar issue:

1 Like

Thanks @Russ_Thomas, the code work very well :partying_face:

1 Like

whenever i used the setproperty its still using the katalon driver and not the specified path to the driver

The last line shows “Chrome Path C:\Program Files\Katalon Studio\configuration\resources\drivers\chromedriver_win32\chromedriver.exe” instead of the one in set property

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

@eric.fabiszewski

You have a misunderstanding.

WebDriver driver = new ChromeDriver()
DriverFactory.changeWebDriver(driver)

KeywordUtil.logInfo('Chrome Path ' + DriverFactory.getChromeDriverPath())

Do you expect that a call to DriverFactory.getChromeDriverPath() will return the path from which the WebDriver instance (named driver) were instanciated?

No. The system does not work as you expect.

The call to DriverFactory.getChromeDriverPath() will always return the path of the chromedriver.exe bundled in the Katalon Studio distribution, which is static and never changes.

Then, is there any way to get the path from which the WebDriver instance named driver was instanciated from? — I am sure that the org.openqa.selenium.WebDriver does not implement such a method. But, as you already know, you are required to set the value of System Property webdriver.chrome.driver before calling new ChromeDriver() so that you are always aware of the path value. You don’t need that magical method.

1 Like