DarkSnake
DarkSnake

Reputation: 41

Change Between Chrome and Firefox per Scenario in Selenium Java ( CUCUMBER , JUnit)

How can i change between browsers when i run a specific scenario in Java?

I already imported the 2 browsers so far i can only open both of them using the code

public void accessURL() throws Throwable
{

    Registration_Steps_1.setUp();
    for(String browser : browserDriver)
    {

        driver=Registration_Steps_1.initiateBrowserDriver(browser);
        //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get(baseUrl);    
        super.driver = driver;

    }

}

after that i cannot run the other methods for each of the browsers

Upvotes: 0

Views: 600

Answers (2)

Prakash Palnati
Prakash Palnati

Reputation: 3409

the next methods might probably be running by the second browser coming from your browserDriver.

driver object will be a fresh instance of webdriver interface and will not have any session.

so, if you want to run a flow involving login with two browsers, it will not be possible as the login session will recorded in the browser with which you logged in.

if it is a general url traversing stuff you can do with two browsers by calling the second browser by instantiating the driver object again in the middle.

Upvotes: 0

Sadik Ali
Sadik Ali

Reputation: 1205

Do you want to run test on both browser if yes, user testng suite and pass browser parameter from testng suite.

Second approach setup browser type in configuration file read from there and run test on browser as mention in configuration file.

Upvotes: 1

Related Questions