maven, spring-boot, cucumber (jvm5), selenium 등으로 테스트 프레임 워크를 설정했습니다. 프레임 워크는 오랫동안 (병렬로) 정상적으로 작동했지만 최근에 유선 동작이 발생했습니다. 두 개의 테스트를 병렬로 실행하면 두 개의 크롬 인스턴스가 시작된 것을 볼 수 있지만 하나의 인스턴스 만 URL을 올바르게 엽니 다 (다른 인스턴스에는 데이터가 있습니다. url 필드에 있음). 해당 크롬 인스턴스에서 동시에 두 개의 테스트가 실행되었습니다. (예 : 입력 상자에 두 개의 다른 사용자 이름을 동시에 입력합니다.)
모든 입력을 환영합니다. 감사합니다.
아래는 병렬에 대한 내 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());
});
}
}
Spring의 컴포넌트는 싱글 톤입니다. 따라서 두 개의 웹 드라이버를 만드는 동안 동일한 개체의 동일한 필드에이를 할당합니다. 이것은 하나만 사용됨을 의미합니다.
아마도 v5로 업그레이드 한 후이 동작이 발생하기 시작했을 것입니다. v5 이후 Cucumber는 다른 모든 스프링 테스트와 마찬가지로 스레드간에 스프링 애플리케이션 컨텍스트를 공유합니다.
https://github.com/cucumber/cucumber-jvm/blob/main/CHANGELOG.md#500-rc4-2019-12-21
구성 요소가 시나리오간에 공유되지 않도록하려면로 주석을 달아야합니다 @ScenarioScope
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다