How to open a second browser without closing the first in Katalon
By default, when you are opening a new browser, it will close the previous one and open a new one. In some cases, we need to do our test activities in both the browsers. As of now Katalon is doing like this. So, we need to do some scripting to achieve this. In this blog, we are going to see how to open a second browser without closing the first. Let’s get into this...!
Create two drivers:
public static WebDriver driver1;
public static WebDriver driver2;
We have to create two different drivers and keep those as a static. So, that you can call anywhere you want across the project.
Create a method to open browser:
public ChromeDriver openChromeBrowser()
{
System.setProperty("webdriver.chrome.driver",DriverFactory.getChromeDriverPath());
return new ChromeDriver();
}
This method will open a chrome browser also it returns a chrome driver which is created in the method. If you want to open any other browser, please configure the method based on your requirement.
Open 1st browser and changing the driver:
driver1 = openChromeBrowser();
DriverFactory.changeWebDriver(driver1);
First line we are calling the method which
we created to open browser. Then we are assigning the chrome that is returned
by that method. Then we are changing the default driver to driver1.
Purpose of changing driver is, we can
directly use Katalon’s methods without any changes.
Open 2nd browser and changing the driver:
driver2 = openChromeBrowser()
DriverFactory.changeWebDriver(driver2)
Here we are doing the same like what we
did it for the 1st browser.
When we open this second browser it won’t close the previous browser. So, you can continue your test case activity on both the browsers.
Sample scenario for better understanding:
Step 1: Open 1st browser (driver in the 1st browser)
Step 2: Create user
Step 3: Open 2nd browser (change the driver to driver2)
Step 4: Login with the created user's credentials
Step 5: Switch to the first browser(change the driver to driver1)
Step 6 : Delete the created user
Thanks for reading, Kindly let us know below in the comment section if you have any..!
Comments
Post a Comment