Skip to main content

How to open a second browser without closing the first in Katalon

 

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

Popular posts from this blog

How to get data from excel sheet based on scenario name in Katalon

How to get data from an Excel sheet based on the Cucumber feature file scenario name in Katalon Studio    For my project, I created some methods to read data from an Excel sheet   based on my cucumber scenario . It is 100% working. By default, Katalon Studio doesn't have any method to get data from an Excel sheet based on the scenario name. So, in this post, I am going to explain how I did it.   Let's get straight into the coding! Create Excel file:         Create an Excel sheet with the column name "Scenario name." Keep this Excel sheet inside your project. Then add it to the data files.             For ex: Create Property file:           Create a property file. In that property file, keep your Excel sheet name like you did in the below image. This is one of the best ways to reduce maintenance work by keeping everythin...