Springboot 中的 Selenium 驱动程序管理

编程入门 行业动态 更新时间:2024-10-27 04:37:03
本文介绍了Springboot 中的 Selenium 驱动程序管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 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 驱动程序管理

本文发布于:2023-10-18 23:42:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1505765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:驱动程序   Springboot   Selenium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!