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

How to exchange session data between step classes #2912

Closed
aybartsch opened this issue Sep 2, 2022 · 3 comments
Closed

How to exchange session data between step classes #2912

aybartsch opened this issue Sep 2, 2022 · 3 comments

Comments

@aybartsch
Copy link

Hi there,

I'm having a cucumber feature file, a test case linked with feature file and step classes, and further step classes. I'd like to exchange serenity session variable between the step classes.

StepClass1:

Object object1 = new Object(); // Pseudo code

@Before
public void setup() {
   Serenity.setSessionVariable("object1").to(object1);
}

StepClass2:

Object object2 ; // Pseudo code

@Before
public void setup() {
   if (Serenity.sessionVariableCalled("object1") != null) {
      object2 = Serenity.sessionVariableCalled("object1");
   }
}

Unfortunately, the session variable "object1" is null when called in StepClass2. How can I solve this problem? And how can I control the order of step classes setups called?

I'm using serenity version 3.2.5.

Thanks and regards, André

@aybartsch
Copy link
Author

aybartsch commented Sep 2, 2022

I found out that "serenity.maintain.session" needs to be set to true. Does this imply the session variable is known in all other running tests of the test suite, too?

It seems that the order I'm defining the "glue" in the test case is defining the order the step classes setups are called. Can you confirm my assumption?

TestClass:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
        features = "classpath:/features/MySerenity.feature",
        glue = {"path.to.step.class.1",
                "path.to.step.class.2",
                "path.to.step.class.3"})
public class MySerenityTest extends BaseTest {
}

@wakaleo
Copy link
Member

wakaleo commented Oct 26, 2022

You can also use the @step(shared=true) annotation to inject shared objects between steps. Milage may vary if you run things in parallel though.

@aybartsch
Copy link
Author

Thanks for the hint.

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

2 participants