Java Webdriver TestNG:返回ArrayList索引
我想得到pdf的测试用例,我有下面的代码 基类: PDF类: 测试用例类: 在测试用例类中,我提到了pdfUtility.WriteTestResultToPdfFileTestResult.pdf,arraylist2;它应该创建包含此类arraylist2.getList3使用的arrayList索引的pdf;和arraylist2.getList0 目前,它生成pdf,但返回基类中的所有索引。Java Webdriver TestNG:返回ArrayList索引,java,pdf,selenium,Java,Pdf,Selenium,我想得到pdf的测试用例,我有下面的代码 基类: PDF类: 测试用例类: 在测试用例类中,我提到了pdfUtility.WriteTestResultToPdfFileTestResult.pdf,arraylist2;它应该创建包含此类arraylist2.getList3使用的arrayList索引的pdf;和arraylist2.getList0 目前,它生成pdf,但返回基类中的所有索引。 请帮助我用测试用例类中使用的索引创建pdf。我已经引用了测试用例类中需要帮助的区域。您正在Pdf
请帮助我用测试用例类中使用的索引创建pdf。我已经引用了测试用例类中需要帮助的区域。您正在PdfUtility.WriteTestResultToPdfFile中使用参数类型as List,并从测试用例类传递ArrayList1 您可以尝试下面的代码来获取TestCase类中使用的索引列表。对基类和测试类进行了微小的更改 在基类中,修改getList方法如下:
public String getList(int pos) {
return list.get(pos);
}
将TestCase类更改为
public class PdfUtility {
public void WriteTestResultToPdfFile(String fileName,List<String> testCase)
throws IOException, COSVisitorException
{
try
{ some code}
}
}
public class Testpdf {
public WebDriver driver;
private ArrayList1 arraylist2;
@Test
public void testclass {
Assert.something...
arraylist2.getList(0);
@AfterSuite
public void tearDown() throws Exception {
PdfUtility pdfUtility=new PdfUtility();
//add time stamp to the resultList
arraylist2.getList(3);
for (int i = 0; i < this.arraylist2.size(); i++) {
/*
want to store indexes used in this class like [0] and [3]
in some variables to use in WriteTestResultToPdfFile method.
*/
}
//write the test result pdf file with file name TestResult
pdfUtility.WriteTestResultToPdfFile("TestResult.pdf", arraylist2());
driver.quit();
public String getList(int pos) {
return list.get(pos);
}
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;
public class Testpdf {
public WebDriver driver;
private ArrayList1 arraylist2 = new ArrayList1();
List<String> listTestClassIndexes = new ArrayList<String>();
PdfUtility pdfUtility = new PdfUtility();
@Test
public void testclass() {
listTestClassIndexes.add(arraylist2.getList(0));
}
@AfterSuite
public void tearDown() throws Exception {
// add time stamp to the resultList
listTestClassIndexes.add(arraylist2.getList(2));
// write the test result pdf file with file name TestResult
pdfUtility.WriteTestResultToPdfFile("TestResult.pdf",
listTestClassIndexes);
driver.quit();
}
}