我正在尝试使用范围报告打印数组列表。但它给我的错误是“ExtentTest类型中的方法日志(LogStatus,Throwable)不适用于参数(LogStatus,ArrayList)”
我正在尝试使用范围报告打印Array-list b。但是它给我的错误是“ExtentTest类型中的方法日志(LogStatus,Throwable)不适用于参数(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)
但现在它只打印:-List-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();
}
}发布于 2019-01-25 05:14:09
@ShehNathMishra帮助我认识到ArrayList不能作为扩展报告的工具。
将Arraylist转换为String builder,然后转换为string helped。固定代码如下:
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());发布于 2019-01-25 04:28:28
我无法从问题中找到关于这个问题的足够信息,也没有足够的声誉来添加评论。
你能提供更多关于Listeners.test的细节吗?
根据上面的信息级别,尝试Listeners.test.log(LogStatus.INFO, b.toString()),因为我可以看到有一个将字符串作为第二个参数的日志方法。
https://stackoverflow.com/questions/54354373
复制相似问题