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

Serenity.setSessionVariable scope for hooks(@BeforeAll) #2704

Closed
sandlok opened this issue Feb 11, 2022 · 4 comments
Closed

Serenity.setSessionVariable scope for hooks(@BeforeAll) #2704

sandlok opened this issue Feb 11, 2022 · 4 comments

Comments

@sandlok
Copy link

sandlok commented Feb 11, 2022

Hi @wakaleo
Thanks for code fix for @BeforeAll and @afterall hookup(3.2.0 version). However I have a use-case where in need to setup
something like this.
@BeforeAll
Serenity.setSessionVariable("token_id").to(accessToken);
The above "token_id" I want to retrieve it in Scenario
Serenity.getCurrentSession().get("token_id")-------This is giving null pointer exception. How to resolve this one

@wakaleo
Copy link
Member

wakaleo commented Feb 11, 2022

Session data is cleared before each session by default. If you want to preserve session data between sessions, you need to set the serenity.maintain.session property to true (see

).

@sandlok
Copy link
Author

sandlok commented Feb 12, 2022

Hi Wakaleo,
Thanks for suggesting link. It worked upon configuring serenity.maintain.session = "true" in conf file. However I have observed one thing here.
If you are running tests without parallel execution its working
If you are running tests parallel, then its not working

@wakaleo
Copy link
Member

wakaleo commented Feb 12, 2022

Looks like it is behaving as expected. If you are running parallel tests, each parallel thread has it's own session. @BeforeAll methods are called in a different thread, and don't have access to the sessions used by the parallel tests. If you need to run your tests in parallel, you can either use a static variable or use a @before method to run at the start of each scenario.

@sandlok
Copy link
Author

sandlok commented Feb 13, 2022

Got it Thanks

@wakaleo wakaleo closed this as completed Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants