Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
1.4k views
by Contributing Tester (26 points)
I am experiencing problems with Cucumber and @After annotations. I am using Cucumber and Java. I want to log out at the end of each Scenario and Scenario Outline. I don't want to have log out at each Then step so I have added it in a tearDown() method in StepDefBasePage to cover the log out part, that is extended to my StepDefinitions.

I have it added to @After method in all Step Definition files. But after it logs out the first time and goes to login screen then it is trying to log out again and it doesn't find the element at log in page.

I have the @After annotation in all Step Definitions files and is it possible that because the same feature is using steps from different Step Definitions to try @After method more than once? How can I solve the issue to log out after each Scenario and each Scenario in Scenario Outline?

Thanks for your help

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer
Usually we have one step definition saying Then logout. So we will have one function implementing logout functionality and we will be calling this logout in each test scenario.

Eg.

Scenario: login logout

Given I am on a home page

When I log in

Then I see dashboard

And I logout

Scenario: Registration

Given I am on a home page

When I register as a new user

Then I see dashboard

And I logout

@After is usually annotation of JUnit of TestNG. You will have hard time using it with Cucumber.

Hope that helps!
by Contributing Tester (26 points)
Thanks for your answer. In this case I will have many scenarios with Then I logout.

I have implemented @After("@TagFromFeatureFile") for each step definition. Hope it works.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...