【发布时间】:2019-02-17 16:57:17
【问题描述】:
我正在尝试使用 selenium webelement 作为参数为函数创建测试用例。
我正在尝试模拟该元素,但这个测试用例给出了错误。我正在尝试制作测试用例的方法是这样的。
@Override
public boolean isDownloadStarted(WebDriver driver) {
boolean isDownloadStarted = false;
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
if (tabs.size() == 1) {
isDownloadStarted = true;
}
return isDownloadStarted;
}
测试用例给出空指针异常
DownloadStatusListenerImpl status;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
status = new DownloadStatusListenerImpl();
}
@Test
public void testDownloadStatusListenerImpl() {
Mockito.when(status.isDownloadStarted(Mockito.any(WebDriver.class))).thenReturn(true);
assertEquals(true, status.isDownloadStarted(Mockito.any(WebDriver.class)));
}
【问题讨论】:
标签: java selenium selenium-webdriver junit mockito