Springboot中的Selenium驱动程序管理

时间:2018-09-22 13:50:39

标签: selenium-webdriver testng spring-boot-test

我正在尝试使用Spring Boot创建一个Selenium框架。我试图实现的目标spring-boot应该管理selenium驱动程序的创建,即使我们并行运行测试,如果可能的话,我也希望避免在页面类构造函数中传递驱动程序对象。 所以我创建了一个像下面的

这样的bean类。
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.2
import "./Components"

Item {
    anchors.fill: parent

    GridLayout {

        columns: 2
        Text { text: qsTr("Date Filter: ") }
        DatePicker {}

        Text { text: qsTr("name filter: ") }
        TextField {}
    }
}

在单项测试中效果很好。但是对于并行的多个测试,我将上述方法的范围更改为原型,并且在运行测试时,它启动了多个测试,但未能按预期工作,并且命令在错误的浏览器中启动。我知道我缺少与线程/并行相关的东西。如果有人可以指导我或在使用spring-boot和硒的情况下共享git repo,那将真的很有帮助。

1 个答案:

答案 0 :(得分:0)

您可以尝试通过以下方式将范围更改为线程:

@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;
}