使用 ExtentReports 打印 Arraylist 时出错

Error while printing Arraylist using ExtentReports

我正在尝试使用范围报告打印数组列表。但它给我错误 "The method log(LogStatus, Throwable) in the type ExtentTest is not applicable for the arguments (LogStatus, ArrayList)"

我正在尝试使用范围报告打印数组列表 b。但它给我错误 "The method log(LogStatus, Throwable) in the type ExtentTest is not applicable for the arguments (LogStatus, ArrayList)"

下面是我的代码,我在这里得到错误 "Listeners.test.log(b);"

import org.testng.annotations.BeforeMethod;
import pages.tablepage;
import utilities.Base;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class Store extends Base{

        @BeforeMethod
        public void initialize() throws IOException {
            driver = initializeDriver();
            Log.info("Driver is initialized");
            driver.get(prop.getProperty("url3"));
        }
        @Test
        public void Sorting() {

            //constructor from Page Object
            tablepage P = new tablepage(driver);

            //page numbers
            int c =  P.page().size();

            //defining lists
            ArrayList<String> b = new ArrayList<String>();

            //Storing values to a List
            for (int i=1;i<=c;i++) {
               int s = P.name().size();
               for(int j=0;j<s;j++) {
               b.add(P.name().get(j).getText());
              }
              if(i<c) {
                 P.page().get(i).click();
                }
            }

            Listeners.test.log(LogStatus.INFO,"---List---" + c); //this prints fine

            Listeners.test.log(b); //this is not working

}
}

我要它打印

---列表--- 4

[初级技术作者、首席执行官 (CEO)、会计师、软件工程师、软件工程师、集成专家、Javascript 开发人员、高级 Javascript 开发人员、区域总监、售前支持, 人事主管, 销售助理, 首席运营官 (COO), 开发人员, 系统管理员, 会计师, 销售助理, 高级营销设计师, 开发主管, 区域总监, 办公室经理, 集成专家, 营销设计师, 首席财务官 (CFO),支持主管、集成专家、开发人员、软件工程师、区域营销、区域总监、系统架构师、首席营销官 (CMO)]

但现在它只是打印: ---名单--- 4

这是我的监听器文件:

import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class Listeners implements ITestListener {

     protected static WebDriver driver;
     protected static ExtentReports reports;
     public static ExtentTest test;
     Base B = new Base();

    public void onTestStart(ITestResult result) {
         System.out.println("Test Started");
          test = reports.startTest(result.getMethod().getMethodName());

         }


    public void onTestSuccess(ITestResult result) {
        System.out.println("Test Success\n");

         }

    public void onTestFailure(ITestResult result) {
        System.out.println("Test Failed\n");
          test.log(LogStatus.FAIL, result.getMethod().getMethodName() + " test failed");
          try {

            //getScreenshot();
}

    public void onStart(ITestContext context) {
          driver = new ChromeDriver(); 
          reports = new ExtentReports(""Extentreports.html");       
    }

    public void onFinish(ITestContext context) {

          reports.flush();

    }

}

我无法从问题中找到关于该问题的足够信息,也没有足够的声誉来添加评论。

您能否提供有关 Listeners.test 的更多详细信息?

根据上面的信息水平,尝试Listeners.test.log(LogStatus.INFO, b.toString())因为我看到有一个将字符串作为第二个参数的日志方法。

@ShehNathMishra 帮助我弄清楚 ArrayList 不能成为范围报告的 arhument。

将 Arraylist 转换为字符串生成器,然后再转换为字符串很有帮助。下面是固定代码:

 StringBuilder sb = new StringBuilder(); 
            for (String s : b)
            {
                sb.append(s);
                sb.append("\t");
            }

            //Sorting the list
            Listeners.test.log(LogStatus.INFO,"--- List---");
            Listeners.test.log(LogStatus.INFO,sb.toString());