问题描述
我无法在基于硒的框架中使用自动装配。这是我的POM依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.9.RELEASE</version>
<scope>runtime</scope>
</dependency>
我的配置文件如下:
@Configuration
@ComponentScan
public class AppConfig {
@Autowired
public WebDriver driver;
@Bean
public WebDriver driver() {
return new ChromeDriver();
}
}
我建立了一个junit规则链,其中外部规则实例化了应用程序上下文:
@Override
public void evaluate() throws Throwable {
ApplicationContext appContext = new AnnotationConfigApplicationContext(AppConfig.class);
WebDriver driver = (WebDriver) appContext.getBean("driver");
base.evaluate();
}
调用appContext.getBean("driver");
确实可以从appContext成功获取驱动程序,但是测试类的自动装配和内部规则均不起作用。驱动程序始终为null。当前所有文件都存在于测试包中,所有规则和测试类都用@Component标注,并且在类中具有@Autowired webdriver属性。在设置Spring时我哪里出错了?
@Autowired
public WebDriver driver;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)