硒:类型不匹配:无法从Class< CustomListeners>到班级< ;?扩展ITestNGListener> [] [英] Selenium: Type mismatch: cannot convert from Class<CustomListeners> to Class<? extends ITestNGListener>[]
问题描述
我正在使用TestNG框架.我有一个扩展BaseTestSuite
的Test1
类.我也有一个实现WebDriverEventListener
的CustomListeners
类.当我在Test类中使用@Listeners(CustomListeners.class)
批注时,出现以下错误.请帮助解决.
I am using TestNG framework. I have a Test1
class which extends BaseTestSuite
. Also I have a CustomListeners
class which implements WebDriverEventListener
. When I use @Listeners(CustomListeners.class)
annotation in the Test class, getting following error. Please help to resolve.
Type mismatch: cannot convert from Class<CustomListeners> to Class<? extends ITestNGListener>[]
测试类
@Listeners(CustomListeners.class) //Error line
public class Test1 extends BaseTestSuite {
LoginPage lp;
TabMenu tm;
@Test(priority = 0, testName = "Verify Login")
public void login() throws Exception {
lp = new LoginPage(driver, test);
tm = new TabMenu(driver, test);
driver.get(Constants.url);
lp.verifyLoginPageLogo();
lp.setUserName("dmin");
lp.setPassword("admin");
lp.clickLoginBtn();
tm.verifyTabMenu();
tm.isCurrentTab("Dashboard");
}
}
监听器类
public class CustomListeners implements WebDriverEventListener {
/*
*
* All Implemented methods
*
*
*/
}
推荐答案
硒不是TestNG的一部分. WebDriverEventListener接口不扩展ITestNGListener.这两个类没有共同之处. TestNG需要一个类来扩展或实现一个侦听器,以使其正常工作. 为了使这两个类结合使用,请使您的类CustomListeners扩展org.testng.TestListenerAdapter类,因为它是唯一的侦听器类,而不是接口,因此您无需实现TestNG方法.
Selenium is not part of TestNG. The WebDriverEventListener interface doesn't extend ITestNGListener. The two classes have nothing in common. TestNG requires a class that extends or implements one of the listeners for this to work. To combine this two classes to work make your class CustomListeners extend the org.testng.TestListenerAdapter class, because it's the only listener class, and not an interface so you would not need to implement TestNG methods.
这应该是您的课程声明:
This should be your class declaration:
public class CustomListeners extends TestListenerAdapter implements WebDriverEventListener
尝试这种解决方法.
这篇关于硒:类型不匹配:无法从Class< CustomListeners>到班级< ;?扩展ITestNGListener> []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!