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

Constructor behavior with @Shared involved #2318

Closed
traumatic opened this issue Nov 29, 2020 · 1 comment
Closed

Constructor behavior with @Shared involved #2318

traumatic opened this issue Nov 29, 2020 · 1 comment
Labels

Comments

@traumatic
Copy link

Hi,

This post is based on the archetype "Sample Serenity project using JBehave and WebDriver" (mvn archetype:generate -Dfilter=serenity) example.

I annotated the variable endUser in class DefinitionSteps with @Shared.

public class DefinitionSteps {

    @Shared
    EndUserSteps endUser;

    @Given("the user is on the Wikionary home page")
    public void givenTheUserIsOnTheWikionaryHomePage() {
        endUser.is_the_home_page();
    }

and added a constructor to class EndUserSteps

public class EndUserSteps {

    DictionaryPage dictionaryPage;

    public EndUserSteps() {
        
        System.out.println("Ups ... I did it again");
    
    }

The example comes with a LookupADefinition.story which contains two scenarios. Usually the constructor of EndUserSteps is to be executed twice. But due to the @Shared annotation I would expect that the constructor would be invoked once only. Is that correct?

Unfortunately, the string "Ups ... I did it again" appears twice in my console output.

I am running the example with <serenity.version>2.3.2</serenity.version> and tried 2.3.8 as well. Furthermore, I did add serenity.maintain.session = true to serenity.properties.

Thanks

@wakaleo
Copy link
Member

wakaleo commented Nov 29, 2020

Shared objects are only shared in the scope of steps in a scenario, not between scenarios.

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

No branches or pull requests

2 participants