我正在尝试使用 spring boot 创建一个 selenium 框架.我试图完成的事情 spring-boot 应该管理 selenium 驱动程序的创建,即使我们并行运行测试,如果可能的话,我想避免在页面类构造函数中传递驱动程序对象.所以我创建了一个像下面这样的bean类
I am trying to create a selenium framework using spring boot. What I am trying to accomplish it spring-boot should manage selenium driver creation, even when we run the test in parallel and if possible I want to avoid passing driver object in page class constructor. So I created a bean class like below
@Bean public WebDriver getDriver(){ return new ChromeDriver(); }它在 Single 测试中运行良好.但是对于并行的多个测试,我将上述方法的范围更改为原型,当我运行测试时,它启动了多个测试,但没有按预期工作,并且命令开始在错误的浏览器中触发.我知道我错过了与线程/并行相关的东西.如果有人可以指导我,或者有人可以分享使用 spring-boot 和 selenium 的 git repo,那将非常有帮助.
it worked fine for the Single test. But for multiple tests in parallel, I changed the scope of the above method to the prototype, and when I ran the test it started multiple tests but it didn't work as I expected and commands started firing in the wrong browser. I know I am missing something related to Thread/parallel stuff. It would be really helpful if someone can guide me or someone can share git repo where spring-boot and selenium are used.
推荐答案您可以尝试将范围更改为线程:
You could try changing the scope to thread with:
@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; }更多推荐
Springboot 中的 Selenium 驱动程序管理
发布评论