我已经用maven、spring boot、cucumber(jvm5)、selenium等建立了一个测试框架。这个框架在很长一段时间内(并行)正常工作,但最近我得到了这种有线行为。当我并行运行两个测试时,我可以看到两个chrome示例已经启动,但是只有一个示例正确地打开了url(另一个有数据;在url字段中)。两个测试同时在chrome示例上执行(e、 g.在输入框中同时键入两个不同的用户名。)
欢迎任何意见。谢谢您。
下面是我的pom.xml并行设置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<parallel>methods</parallel>
<!--<threadCount>4</threadCount>-->
<useUnlimitedThreads>true</useUnlimitedThreads>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
-Xmx1024m -XX:MaxPermSize=256m
</argLine>
<systemPropertyVariables>
<allure.results.directory>${project.build.directory}/allure-results
</allure.results.directory>
</systemPropertyVariables>
</configuration>
....
</plugin>
以下是跑步者课程:
@RunWith(Cucumber.class)
@CucumberOptions(
strict = true,
features = {"src/test/resources/features"},
plugin = {
"pretty",
"html:target/cucumber-html-report",
"json:target/cucumber/cucumber.json",
"junit:target/cucumber/cucumber.xml",
"io.qameta.allure.cucumber5jvm.AllureCucumber5Jvm",
"rerun:target/rerun.txt"
},
glue = {"com.demo.bss.steps", "com.demo.bss.hook"},
stepNotifications = true,
monochrome = true,
tags = {"not @deprecated"})
public class CukeTest {
}
以下是步骤定义:
//Globel step state class
@Component
public class GlobalStepState {
protected WebDriver driver;
protected WebDriverWait wait;
protected LoginPage loginPage;
protected CrmMainPage crmMainPage;
protected ProdCatalogMainPage prodCataPage;
@Value("${spring.url.bss}")
protected String url;
}
//Global shared stepdefs
public class GlobalStepDef implements En {
@Autowired
GlobalStepState state;
@Autowired
CukeHook cukeHook;
public GlobalStepDef() {
Before(
1,
() -> {
state.driver = cukeHook.getWebDriver();
state.wait = new WebDriverWait(state.driver, 30);
state.loginPage = new LoginPage(state.driver);
state.crmMainPage = new CrmMainPage(state.driver);
state.prodCataPage = new ProdCatalogMainPage(state.driver);
});
Given("^open COMARCH BSS login page$", () -> {
state.driver.get(state.url);
});
}
}
//normal stepdefs
public class LoginStepDefs implements En {
@Autowired
private GlobalStepState state;
public LoginStepDefs() {
When("^I login with a user \"([^\"]*)\" and \"([^\"]*)\"$", (String email, String password) -> {
state.loginPage.inputEmail.sendKeys(email);
state.loginPage.inputPassword.sendKeys(password);
state.loginPage.btnLogin.click();
});
Then("^the (.*) user name show display as (.*)$", (String type, String userName) -> {
WebElement eleUserName = type.equals("CRM") ? state.crmMainPage.strCrmUserName : state.prodCataPage.strCatalogUserName;
state.wait.until(ExpectedConditions.visibilityOf(eleUserName));
Assert.assertEquals(userName, eleUserName.getText());
});
}
}
1条答案
按热度按时间2fjabf4q1#
spring中的组件是单例的。因此,当您创建两个webdriver时,您将它们分配给同一对象的同一字段。这意味着只使用一个。
大概您在升级到v5之后就开始遇到这种行为了。因为v5将在线程之间共享spring应用程序上下文(就像所有其他spring测试一样)。
https://github.com/cucumber/cucumber-jvm/blob/main/changelog.md#500-rc4-2019-12-21
为了确保组件不会在场景之间共享,您必须使用
@ScenarioScope
.https://github.com/cucumber/cucumber-jvm/tree/main/spring