-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Awaitability.await() method unable to access ScenarioScope bean in cucumber-spring 6.10.2, it was working till cucumber-spring 4.8.1 #2647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Assuming Awaitility waits on a different thread that sounds plausible. The How did you establish a bean is being created only once |
How did you establish a bean is being created only once objObject is referenced (i.e when objObject.isDisplayed() is called)? |
But how did you establish this is in fact what happens? Can you explain what observations you made and how you reached your conclusion? And were you able to see that this happened on a different thread? Please bear in mind that you are trying to explain your problem to a complete stranger with a cell phone and some spare time while the food is in the oven. 😄 |
To reproduce the problem use: public class ExampleSteps {
@Autowired
private ScenarioScopedContainer container;
@Given("some step")
public void some_step() {
UUID s = container.getId();
Awaitility.await().until(() -> {
assertEquals(s, container.getId());
return true;
});
}
} The assertion will fail when used in combination with: @ScenarioScope
@Component
public class ScenarioScopedContainer {
private final UUID id = UUID.randomUUID();
public UUID getId() {
return id;
}
} However it will pass when using The difference between public @interface ScenarioScope {
@AliasFor(
annotation = Scope.class)
ScopedProxyMode proxyMode() default ScopedProxyMode.TARGET_CLASS;
} Because the Combined with:
We end up attempting to create a new scope for awaitilities thread. |
The motivation for using And this is also the solution to your problem. If your scenario scoped objects are only reachable through step definition classes and are not leaked into the application context you can either use |
Hi @mpkorstanje, highly appreciate your time in analysing the problem in simple terms and recommending the solution with an example. However, there are some more challenges attached to it. Consider below given points first:
|
It's a feature of Spring to reuse the Application context between tests. Not just for Cucumber, but also for example for JUnit. Until #1846 (reference) Cucumber would override some of Springs internals to prevent this. But ultimately that was the wrong choice. You may want to reconsider if Spring is the right dependency injection framework for you. If you aren't testing a Spring application
Could you provide a concrete example of this? Since these objects are only accessible through the already Scenario scoped step definitions it is not immediately apparent to me how any state would be leaked. |
Hi, thanks a lot for your guidance and support. Sorry for delay in my
response, my framework structure is almost same to this one. Differences
are: cucumber version we are using is 6.10.2, and we are creating webdriver
bean similarly, with @ScenarioScope.
https://github.com/soraiareis/demo-spring-selenium
…On Mon, 28 Nov 2022, 00:41 M.P. Korstanje, ***@***.***> wrote:
It's a feature of Spring to reuse the Application context between tests.
Not just for Cucumber, but also for example for JUnit. Until #1846
(reference)
<#1846 (reference)>
Cucumber would override some of Springs internals to prevent this. But
ultimately that was the wrong choice.
You may want to reconsider if Spring is the right dependency injection
framework for you. If you aren't testing a Spring application
cucumber-pico or cucumber-guice may be more suitable. Unlike Spring, with
these frameworks each scenario has it's own.
if we change @ScenarioScope proxy mode as per your recommendation in no 1
(above), then Cucumber will leak thread state and parallel run using
Surefire will malfunction
Could you provide a concrete example of this? Since these objects are only
accessible through the already Scenario scoped step definitions it is not
immediately apparent to me how any state would be leaked.
—
Reply to this email directly, view it on GitHub
<#2647 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFSLLM7LR2XQ7T4DYUMLJEDWKP5TTANCNFSM6AAAAAASLNDCUM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi,
I am working on migrating our framework from cucumber 4.8.1 to 6.10.2, and we use Spring, Java, Junit, Webdriver. As part of this work, I have added @ScenarioScope annotation across our java classes (pageObjects and pageActions) which were earlier annotated with @scope(SCOPE_CUCUMBER_GLUE). I am able to run the automation scripts, but the run fails as soon as code founds any await() method and the execution control enters into it. In the process await() creates a singleton bean and it cannot access any pageObjects that are scenario scoped. The error message says, ScopeNotActiveException. Given below sample code:
Did anyone used Awaitability.await() in cucumber-spring v6.10.2 and above? Could you kindly guide me?
We have been using Awaitability.await() with cucumber-spring 4.8.1 and that works.
The text was updated successfully, but these errors were encountered: