Springboot 中的 Selenium 驱动程序管理 [英] Selenium driver management in Springboot

查看:56
本文介绍了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 驱动程序管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆