@Test 方法无法在 TestNG class 中注入多个 classes
@Test method are not able to inject with multiple classes in TestNG class
我用 TestNG classes 创建了一个 Maven 项目。在 TestNG.xml 中,我给出了套件名称。我已经使用多个浏览器 Chrome 和 Firefox 运行 并行。只需设置 class 和一个 class 就可以正常工作,但是当我包含多个带有 @Test
注释的 class 时,我将得到一个注入错误并给出一个错误。
我会提供我试过的代码
Setup.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 {
}
我得到的错误是:
Cannot inject @Test annotated Method [valid_test] with [class org.openqa.selenium.remote.DesiredCapabilities].
预计 运行 两个测试用例 valid_logintest 和 valid_test
很可能你的项目某处有一个函数,看起来像:
@Test
public void sometest(DesiredCapabilities caps) {
}
这不是正确的参数化方式TestNG test methods, you should remove this DesiredCapabilities argument from the method annotated with @Test
如果你想将外部参数传递给用 @Test
注释的方法,你应该使用 @Parameters
annotation
我想 @Test
注释应该在 non-static 方法上。
我用 TestNG classes 创建了一个 Maven 项目。在 TestNG.xml 中,我给出了套件名称。我已经使用多个浏览器 Chrome 和 Firefox 运行 并行。只需设置 class 和一个 class 就可以正常工作,但是当我包含多个带有 @Test
注释的 class 时,我将得到一个注入错误并给出一个错误。
我会提供我试过的代码
Setup.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 {
}
我得到的错误是:
Cannot inject @Test annotated Method [valid_test] with [class org.openqa.selenium.remote.DesiredCapabilities].
预计 运行 两个测试用例 valid_logintest 和 valid_test
很可能你的项目某处有一个函数,看起来像:
@Test
public void sometest(DesiredCapabilities caps) {
}
这不是正确的参数化方式TestNG test methods, you should remove this DesiredCapabilities argument from the method annotated with @Test
如果你想将外部参数传递给用 @Test
注释的方法,你应该使用 @Parameters
annotation
我想 @Test
注释应该在 non-static 方法上。