有什么方法可以在TestNG报告摘要中显示我的DataProvider值?

时间:2019-06-26 15:48:21

标签: java selenium testng dataprovider testng-dataprovider

基本上,我在LambdaTest Selenium Grid上以多种配置运行自动化测试。我在testng测试套件中添加了7个测试类文件。我在DataProvider类中传递了诸如浏览器,浏览器版本,操作系统和分辨率之类的配置。每个测试将在DataProvider类中通过的所有配置上运行。但是,我无法在testng emailable-report的摘要部分中获得那些配置值。

我想要的是拥有DataProvider类文件-testng emailable-report的摘要部分中的配置值,这将有助于我了解每个测试通过或失败的配置。

到目前为止,我的testng报告如下:https://ibb.co/5TbDdGw

在顶部显示了在7个不同的类文件中添加的7个测试用例。

package com.mydataprovider;

import org.testng.annotations.DataProvider;

public class MyDataProvider {

@DataProvider
public Object[][] realTimeConfiguration() {
    return new Object[][] { 

        new Object[] {"chrome", "chrome76","win10","1280x1024" },
        new Object[] {"chrome", "chrome75","win10","1280x1024" },
        new Object[] {"chrome", "chrome74","win10","1280x1024" },
        new Object[] {"chrome", "chrome73","win10","1280x1024" },
        new Object[] {"chrome", "chrome72","win10","1280x1024" },


        new Object[] {"firefox", "firefox68","win10","1280x1024" },
        new Object[] {"firefox", "firefox67","win10","1280x1024" },
        new Object[] {"firefox", "firefox66","win10","1280x1024" },
        new Object[] {"firefox", "firefox65","win10","1280x1024" },
        new Object[] {"firefox", "firefox64","win10","1280x1024" },

        };
    }
}

这是我的DataProvider类,其中包括配置。 在共享的报告屏幕截图中,它显示了所有测试方法都在DataProvider中提到的所有10种配置上运行。但是,报告摘要中并未显示该配置,即我的每个测试都在哪个配置上运行。

请帮助生成包含在testng报告摘要中的DataProvider值的报告。

2 个答案:

答案 0 :(得分:0)

您可以将它们添加到测试的描述中。

@Test(dataProviderClass = DataProviderClass.class, dataProvider = "dataProviderMethod")
public void testMethod(String param1, String param2, String param3, String param4) {
    ITestResult result = Reporter.getCurrentTestResult();
    result.getMethod().setDescription(param1 + " " + param2 + " " + param3 + " " + param4);
}

答案 1 :(得分:0)

我已针对您针对文章撰写的代码尝试了您的dataProvider,在该文章中您发表了评论- https://www.swtestacademy.com/change-test-name-testng-dataprovider/

我得到了以下结果-

PASSED: testRenaming_chrome76("chrome", "chrome76", "win10", "1280x1024")
PASSED: testRenaming_chrome75("chrome", "chrome75", "win10", "1280x1024")
PASSED: testRenaming_chrome74("chrome", "chrome74", "win10", "1280x1024")
PASSED: testRenaming_chrome73("chrome", "chrome73", "win10", "1280x1024")
PASSED: testRenaming_chrome72("chrome", "chrome72", "win10", "1280x1024")
PASSED: testRenaming_firefox68("firefox", "firefox68", "win10", "1280x1024")
PASSED: testRenaming_firefox67("firefox", "firefox67", "win10", "1280x1024")
PASSED: testRenaming_firefox66("firefox", "firefox66", "win10", "1280x1024")
PASSED: testRenaming_firefox65("firefox", "firefox65", "win10", "1280x1024")
PASSED: testRenaming_firefox64("firefox", "firefox64", "win10", "1280x1024")
  • 我已在BeforeMethod中更改为testData [1]以在testName中打印浏览器版本,还将Test中的参数增加到4而不是1。