-
-
Notifications
You must be signed in to change notification settings - Fork 513
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
can't we use static variables for parallel execution in serenity framework #3442
Comments
Use ThreadLocals. |
Thank you @wakaleo |
It's a standard Java feature: https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html. You can also use the Serenity session variables, e.g
|
thank you, |
Serenity session variables are thread safe (they use thread locals) |
ok Thank you |
Hi @wakaleo , i have tried Serenity session variables didn't work for me, i was calling a feature line where i used to retrieve dynamic data and storing it in map using Serenity.setSessionVariable("color").to("dynamicdata"); and then calling the data by using Serenity.sessionVariableCalled("color"); , then after some feature line (we used to do some apllication navigations) then need to retrieve same data using Serenity.sessionVariableCalled("color"); now it's returning null, can you help me to resolve this issue. Example: Thanks in Advance |
Are you calling these in the same scenario? |
yes |
yes scenario, but calling in different methods |
That should work fine then. Here's an example:
|
can we call Serenity.setSessionVariable("todoItems").to(items); and List originalItems = Serenity.sessionVariableCalled("todoItems"); in page classes like below A a=new A(); @given("{actor} has a todo list containing {items}") page classs: class A(){ public void storevalues(Actor actor, List items){ }} Class B(){ public void retrievevalues(List expectedItems){
} |
Yes, it doesn't matter what class the methods are in as long as they are executed in the same thread. |
is there any way we can check that they are executed in the same thread or not. i am executing two testcases both are using same methods because of that testcases were failing(static variables), if i execute single testcase(using serenity sessionvariables) also capture data was not getting displayed. iam using java selenium |
Are you trying to share data between test cases or within a single test case? |
with in a single testcase only. Example: Class A(){ public static Map<String, List> agingDetailsforAppointment = new HashMap<String, List>(); public void capturedata(){ } } Class B(){ public void retrievevalues(){ agingDetailsforAppointment.get("id"); // every testcase we are capturing new data and validating here }} same variables but independent testcases, capturing data in same testcase and validating data also in that testcase only |
Either the Serenity session data or native ThreadLocals should work fine for that (I use it all the time) - if it is not, there may be an issue in your test logic. |
Closing presumed answered |
when we are using static variables (Maps and list) and executing test cases parallelly ,since we are using same static variables across all testcases, testcases were failing is there any way that we can handle this.
Thanks in Advance
The text was updated successfully, but these errors were encountered: