简体   繁体   中英

Selenium: Dependency injection does not work

In my java spring mvc, I am trying to make test using cucumber nad selenium. I have the following class, which is responsible for invoking the driver.

@Service
public class BaseUtil {

  public void caller(){
      System.out.println("Caller Firefox driver here!!!!!!!");
  }

}

and then in step definition class i am going to make the dependency injection into the steps:

 @Component
public class StepDefenitions{

    @Autowired
     BaseUtil base;


    @Given("^I want to register into the main forum$")
    public void i_want_to_register_into_the_main_forum() throws Throwable {
        base.caller();

    }}

But it complains with

java.lang.NullPointerException
        at com.exercise.StepDefenitions.i_want_to_register_into_the_main_forum(StepDefenitions.java:26)

So, why the @Autowierd does not work here?

StepDefenitions needs to be a managed bean to have its dependencies injected.

Annotate it with @Component or @Service.

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