0
votes

I'm trying to run my tests on several browsers (Chrome, Edge, Firefox etc.)

I don't need them to run parallel, they can run one after one is finished. I'm using init browser at @before and switch case to look for the browser in the XML config file (getData function).

@BeforeClass
public static void openBrowser() throws ParserConfigurationException, SAXException, IOException {
    initBrowser(getData("BrowserType"));
    mainWindowHandle = driver.getWindowHandle();
    wait = new WebDriverWait(driver, Long.parseLong(getData("WaitTime")));
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    initExtentReport();
    initElements();
}

public static void initBrowser(String browserType) throws ParserConfigurationException, SAXException, IOException {
    switch (browserType.toLowerCase())
        {
        case "firefox":
             driver = initFFDriver();
             break;

        case "ie":
             driver = initIEDriver();
             break;

        case "chrome":
             driver = initChromeDriver();
             break;

             default:
                 driver = initChromeDriver();
                 break; 
    }

    driver.manage().window().maximize();        
    driver.get(getData("URL"));
    driver.manage().timeouts().implicitlyWait(Integer.parseInt(getData("WaitTime")), TimeUnit.SECONDS);
}

However since the test go to check the XML to see what browser I have in the BrowserType (XML)

<Pre>
    Chrome
</Pre>

there is no way for me to run the test on several browsers. I need to change manually the browser in XML to do so.

Is there a way to do this with Junit? (I'm using Java in Eclipse.)

1
This is not an answer to your question, but are you aware that inside InitBrowser you are setting the implicit wait timeout based on the spreadsheet setting, but then in the @BeforeClass after initializing that driver, you are over-riding it with a hard-coded wait of 20 seconds? - Bill Hileman
More along the line of your question, I accomplished this by creating a front-end which allows the tester to select which browser along with a variety of other options, which then creates text table files with those settings, but then that's because I use JBhave which uses JUnit in conjunction with story files (BDD) and those parameters are then subsequently passed to my tests without having to change scripts. Other simpler interfaces just use a spreadsheet to set all those parameters, same idea. - Bill Hileman
Hey, yea i saw the thing about the implicit wait, thanks i will remove one. i didn't quite understand your 2nd part of the answering. - N.P

1 Answers

0
votes

You can create multiple XML each one for different browsers.