我陷入了空指针异常问题。这些测试是通过JUnit运行的,但是我没有设法正确调试并找出原因。
测试课程
CASE
WHEN hits.dataSource = 'app' THEN 'YES'
ELSE 'NO'
END AS Application
Excel Action(Webdriver部分)
ExcelActions excelActions;
Excel_Import excel_import;
@Test
public void addResultsToExcel() throws InterruptedException {
searchAfterLogin(); // works fine until the next method
excelActions.addToExcel(); //thats where NPE begins...
excel_import.importExcel(excelActions.addToExcel());
}
Excel导入类
public class ExcelActions extends BaseAction {
public ExcelActions(WebDriver driver) { super(driver); }
public Map<String, Object[]> addToExcel(){
String beforeXpath_pageName = "//*[@id=\"mw-content-
text\"]/div[3]/ul/li[";
String afterXpath_pageName = "]/div[1]/a";
int rowCount ;
rowCount = 20;
Map<String, Object[]> data = new TreeMap<String, Object[]>();
for(int i = 1; i <= rowCount; i++){
String actualXpath_pageName = beforeXpath_pageName + i +
afterXpath_pageName;
String pageName =
driver.findElement(By.xpath(actualXpath_pageName)).getText();
System.out.println(pageName);
data.put("" + i, new Object[]{pageName});
}
return data;
}
}
你们能看看吗?
答案 0 :(得分:1)
字段:
ExcelActions excelActions;
未初始化。您应该为其分配一个ExcelActions实例,例如:
ExcelActions excelActions = new ExcelActions(someWebDriverMock);
在类中声明字段是不够的。您需要为其分配一些特定的对象,否则将为null
。