Selenium webdriver Springboot中的Selenium驱动程序管理

Selenium webdriver Springboot中的Selenium驱动程序管理,selenium-webdriver,testng,spring-boot-test,Selenium Webdriver,Testng,Spring Boot Test,我正在尝试使用SpringBoot创建一个selenium框架。我试图完成的是spring boot应该管理selenium驱动程序的创建,即使我们并行运行测试,如果可能的话,我希望避免在页面类构造函数中传递驱动程序对象。 所以我创建了一个bean类,如下所示 @Bean public WebDriver getDriver(){ return new ChromeDriver(); } 它在单一测试中运行良好。但对于并行的多个测试,我将上述方法的范围更改为原型,当我运

我正在尝试使用SpringBoot创建一个selenium框架。我试图完成的是spring boot应该管理selenium驱动程序的创建,即使我们并行运行测试,如果可能的话,我希望避免在页面类构造函数中传递驱动程序对象。 所以我创建了一个bean类,如下所示

@Bean
public WebDriver getDriver(){
            return new ChromeDriver();
}

它在单一测试中运行良好。但对于并行的多个测试,我将上述方法的范围更改为原型,当我运行测试时,它启动了多个测试,但没有如我所预期的那样工作,命令开始在错误的浏览器中启动。我知道我遗漏了一些与线程/并行相关的东西。如果有人可以指导我,或者有人可以在使用spring boot和selenium的地方共享git repo,这将非常有帮助。

您可以尝试将范围更改为线程:

@Bean
@Scope(value = "thread", proxyMode = ScopedProxyMode.TARGET_CLASS)
public WebDriver getDriver(){
            return new ChromeDriver();
}

@Bean
public static CustomScopeConfigurer customScopeConfigurer()
{
    CustomScopeConfigurer scopeConfigurer = new CustomScopeConfigurer();
    Map<String, Object> scopes = new HashMap<>();
    scopes.put("thread", SimpleThreadScope.class);
    scopeConfigurer.setScopes(scopes);
    return scopeConfigurer;
}
@Bean
@范围(value=“thread”,proxyMode=ScopedProxyMode.TARGET\u类)
公共WebDriver getDriver(){
返回新的ChromeDriver();
}
@豆子
公共静态CustomScopeConfigurer CustomScopeConfigurer()
{
CustomScopeConfigurer scopeConfigurer=新的CustomScopeConfigurer();
映射范围=新的HashMap();
scopes.put(“线程”,SimpleThreadScope.class);
范围配置器。设置范围(范围);
返回范围配置器;
}

你能解释一下你想如何退出驱动程序吗?由于自定义范围不支持destroyMethod,我想知道如何实现它!