java - @Test 方法无法在 TestNG 类中注入多个类
问题描述
我创建了一个带有 TestNG 类的 Maven 项目。在 TestNG.xml 中,我给出了套件名称。我使用了多个浏览器 Chrome 和 Firefox 来并行运行。只需使用设置类和另外一个类,它就可以正常工作,但是当我包含多个带有@Test
注释的类时,我会收到注入错误并给出错误。
我将提供我尝试过的代码
安装程序.java
if (browser.equals("Firefox")) {
/*the path of the gecko driver is set*/
System.setProperty("firefoxpath");
drfirefox=DesiredCapabilities.firefox();
drfirefox.setBrowserName("firefox");
drfirefox.setPlatform(Platform.WINDOWS);
} else {
/*the path of the chrome driver is set*/
System.setProperty("chrome path");
drchrome=DesiredCapabilities.chrome();
drchrome.setBrowserName("chrome");
drchrome.setPlatform(Platform.WINDOWS);
}
logintest_valid.java
@Test
public static void valid_logintest ()throws MalformedURLException, InterruptedException {
}
@Test
public static void valid_test ()throws MalformedURLException, InterruptedException {
}
我收到错误消息:
无法使用 [class org.openqa.selenium.remote.DesiredCapabilities] 注入 @Test 注释方法 [valid_test]。
期望同时运行测试用例 valid_logintest 和 valid_test
解决方案
很可能您的项目中某处有一个函数,如下所示:
@Test
public void sometest(DesiredCapabilities caps) {
}
这不是参数化TestNG 测试方法的正确方法,您应该从使用@Test注释的方法中删除此DesiredCapabilities参数
如果要将外部参数传递给带有注释的方法,@Test
则应使用@Parameters
注释
推荐阅读
- java - 创建服务bean Spring boot
- amazon-web-services - 我尝试通过 python 创建 S3 存储桶但语法无效
- javascript - 在使用数据库数据更新上下文后,React 'useContext' 挂钩不会重新渲染
- java - 如何获得 PrefixQuery 找到的词的位置?
- php - 如何给一个href以重定向到worpdress中的页面?
- python - 将多个模块从子文件夹导入到另一个文件夹
- grep - 有没有办法通过任何方法仅过滤 .png 文件?
- javascript - 我应该如何根据数组参数在函数中传递来增加 && 运算符的数量?
- recaptcha - Google 不可见的 Recaptcha 令牌和验证端点托管在不同的域中
- python - Pandas 在固定时间窗口内呈指数加权移动平均线