简体   繁体   中英

@Test method are not able to inject with multiple classes in TestNG class

I have created a Maven Project with TestNG classes. In TestNG.xml I have given the suite name . I have used multiple browsers Chrome and Firefox to run parallel. Just with setup class and one more class it works fine but when I include multiple classes with @Test annotation I will get an inject error and will gives an error.

I will provide the code which i have tried

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 {   

    }

I am getting error as:

Cannot inject @Test annotated Method [valid_test] with [class org.openqa.selenium.remote.DesiredCapabilities].

Expect to run both test cases valid_logintest and valid_test

Most probably you have a function somewhere in your project which looks like:

@Test
public void sometest(DesiredCapabilities caps) {  
}

This is not correct way of parameterising TestNG test methods , you should remove this DesiredCapabilities argument from the method annotated with @Test

If you want to pass an external argument to the method annotated with @Test you should be using @Parameters annotation

我想说@Test批注应该在非静态方法上。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM