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

Getting Feature level Tags in Runtime? #3432

Open
zainafzal-tek opened this issue Apr 4, 2024 · 11 comments
Open

Getting Feature level Tags in Runtime? #3432

zainafzal-tek opened this issue Apr 4, 2024 · 11 comments
Labels

Comments

@zainafzal-tek
Copy link

I would like to retrieve the feature level tag during runtime to have a conditional assert. I am currently trying to use

StepEventBus.getParallelEventBus().getBaseStepListener().latestTestOutcome().get().getTags();

But every time it returns nothing. This is a Serenity Cucumber Framework on the latest versions of Junit 5 and Serenity. I am calling this in a actions class with a method annotated with the @step notation. I have not been able to find anything and the only solution I did find was in the archived repo for serenity cucumber.

@zainafzal-tek zainafzal-tek changed the title Getting Feature level Tags in Runtime Getting Feature level Tags in Runtime? Apr 4, 2024
@wakaleo
Copy link
Member

wakaleo commented Apr 4, 2024

This won't work because with JUnit 5 and Cucumber we don't have the current test outcome during the test (it is only assembled after the tests are completed). Why don't you use Cucumber hooks for this?

@zainafzal-tek
Copy link
Author

zainafzal-tek commented Apr 4, 2024

I have not yet tried Cucumber hooks and our current implementation of the step defs follow older standards. So I dont know how that would work. Even with the implementing the hooks what would I call to get the tag being run? Or is that just a deprecated feature atm?

EDIT:
If i call the Feature class and get the feature tags in the @before hook would that work? is there a way to set it up globally, I remember using @BeforeAll in the past to set up webdriver but that was vanilla cucumber selenium with webdriverfactory custom implementation. If i do use @BeforeAll it wouldnt change any other setup steps? if it does how do i achieve a global @before hook

@wakaleo
Copy link
Member

wakaleo commented Apr 4, 2024

You can pass a Scenario parameter - see https://cucumber.io/docs/cucumber/api/?lang=java#hooks

@zainafzal-tek
Copy link
Author

Replied above but that applies to a Scenario, I dont think it returns feature level tags i could be wrong tho?

@wakaleo
Copy link
Member

wakaleo commented Apr 4, 2024

It will return any tags applicable to that scenario, no matter what level they are defined at.

@zainafzal-tek
Copy link
Author

Understood. Will try that out.

@zainafzal-tek
Copy link
Author

zainafzal-tek commented Apr 4, 2024

using

private static Set<String> getTags; @Before public static void before(Scenario scenario){ getTags.addAll(scenario.getSourceTagNames); }

is returning a nullpointer. Keeps complatining that there is a null value hence it doesnt want to initialize the test

@wakaleo
Copy link
Member

wakaleo commented Apr 4, 2024

You would need to check the Cucumber docs or forums, but I don't think it should be a static.

@zainafzal-tek
Copy link
Author

You might be right. let me try removing that.

@zainafzal-tek
Copy link
Author

Still returning the same error even after removing the static.

@wakaleo
Copy link
Member

wakaleo commented Apr 4, 2024

That is managed by Cucumber so the Cucumber folks might have some ideas - I've used tags in the past like that but I don't recall where.

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