Skip to content
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

3.8.1 : correct environmental variables are provided only for the very first test #3177

Open
TagiraNara opened this issue Jun 29, 2023 · 7 comments

Comments

@TagiraNara
Copy link

Hi, I updated the serenity version from 3.4.2 to 3.8.1 and now I have the following problem.
The first test using the environmental variable (url) to open the page in the browser runs normally,
however, all following are failing with:
net.serenitybdd.screenplay.actions.UnknownPageException

This happens because starting from the second test
private EnvironmentStrategy environmentStrategyDefinedIn(EnvironmentVariables environmentVariables)
returns USE_NORMAL_PROPERTIES, while the first running test gets: ENVIRONMENT_CONFIGURED_AND_NAMED

this happens, of course, not without the reason. when the first running test gets to
public OpenPageWithName(String pageName)
the public static EnvironmentVariables currentEnvironmentVariables() returns environmentValiables, containing those which are started with "environments.", (all in all in the test repo I've created for this issue) 85, while the next one only 60.

The test repo to reproduce is:
https://github.com/TagiraNara/TestSerenity

@TagiraNara
Copy link
Author

updated the repo, the problem definitely exists also in rest interactions.
So, in general, the environmental specific configuration is received successfully only with the first test, and never after.
You can use dev profile to run both UI and Rest tests, or run specific test file with the IDE runner (specifying -Denvironment=dev), only the first test will succeed.

@TagiraNara TagiraNara changed the title 3.8.1 : net.serenitybdd.screenplay.actions.UnknownPageException starting from the second test 3.8.1 : correct environmental variables are provided only for the very first test Jul 3, 2023
@wakaleo
Copy link
Member

wakaleo commented Jul 3, 2023

Thanks for identifying this issue. Can you propose a PR for a fix?

@TagiraNara
Copy link
Author

@wakaleo honestly I'm not that sure, according my investigation it comes from the fact that different threads set the environmentVariables differently (but I could not identify the moment, when it happened), and I have some doubts I can correctly resolve it. I will give it a try, but with the current lack of time it won't be soon.

@xmj
Copy link

xmj commented Jul 20, 2023

This may be an improbable lead but I dug into a few reports ( #3165 , #3017 -- they seem linked)
that makes it seem like this regression was introduced somewhere around 3.6.1 with the introduction of Selenium 4.6.

So I was looking at the diff of everything from Then, to current main branch - https://github.com/serenity-bdd/serenity-core/compare/4f3e2ca..main - and searched for environment.

I found this file: https://github.com/serenity-bdd/serenity-core/blob/main/serenity-model/src/main/java/net/serenitybdd/core/environment/ConfiguredEnvironment.java

which

  1. uses ThreadLocal
  2. exposes a method getConfiguration() which is called in quite a number of places
  3. exposes a method updateConfiguration() which is called nowhere (outside of testcases to show that it would, in fact, work)
  4. exposes a method reset() which is called when in the setup of
    serenity-core/src/test/groovy/net/serenitybdd/core/webdriver/WhenInjectingWebdriverInstancesIntoATestCase.groovy
    and the cleanup of serenity-core/src/test/java/net/thucydides/core/webdriver/WhenObtainingTheOutputDirectory.java

@wakaleo
Copy link
Member

wakaleo commented Jul 20, 2023

Have you tried with version 3.9.7?

@xmj
Copy link

xmj commented Jul 20, 2023

Now I did. This is where it gets interesting: the second test seems to run with webdriver.base.url - which makes the undefined URL errors for PageObject go away. Note this is an educated guess as the base url is the only URL configured in serenity.conf which generates the (server-side) error I can see in the screenshots.

But that isn't in fact the URL I would have expected (or, configured in the class extending PageObject).

@xmj
Copy link

xmj commented Sep 4, 2023

The underlying issue seems to be fixed, at least in v4.0.1 the environments will be passed on to the second and third tests correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants