简体   繁体   中英

Combining dataproviders TestNG

I have read a few stackoverflow posts about combining dataproviders but I cant't get anything to work.

What I'm currently doing is a selenium test that takes screenshots of every language the site is translated to. It simply clicks through every link while taking screenshots of it, then it switches the URL to another language and repeat.

My problem is when doing this I can't redirect my screenshots to a specific folder per "language test". To do this I need a second dataprovider, but I already have a dataprovider for this test method for running a different URL per test.

So I need to combine these two dataproviders somehow. They currently look like this

 public static Object [][] language(){
    return new Object[][]{
        {"https://admin-t1.taxicaller.net/login/admin.php?lang=en"},
        {"https://admin-t1.taxicaller.net/login/admin.php?lang=sv"},
        };

}



public static Object [][] directory(){
    return new Object[][]{
        {"screenshotsEnglish.dir"},
        {"screenshotsSwedish.dir"},

        };
}

In my test class I just want to reach these two by writing

 driver.get(**url**);
// This is the screenshot method. Where "Directory" is written I decide where to save the screenshots
     Properties settings = PropertiesLoader.fromResource("settings.properties");  
         String screenshotDir = settings.getProperty(**directory**);
         screenShooter = new ScreenShooter(driver, screenshotDir, "en");

Hope I have made myself clear, appreciate all help!

Regards

public static Object[][] dp() {
    return new Object[][]{
        {
            "https://admin-t1.taxicaller.net/login/admin.php?lang=en",
            "screenshotsEnglish.dir"
        },
        {
            "https://admin-t1.taxicaller.net/login/admin.php?lang=sv",
            "screenshotsSwedish.dir"
        }
    };
}

@Test(dataProvider = "dp")
public void t(String url, String directory) {
    driver.get(url);
    Properties settings = PropertiesLoader.fromResource("settings.properties");  
    String screenshotDir = settings.getProperty(directory);
    screenShooter = new ScreenShooter(driver, screenshotDir, "en");
    /*...*/
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM