Question

I have started to use Specflow, Selenium and PageObject pattern for testing. I would like to make scenarios independent of each other, but when I start running my test features, I see that my user is not anonymous after the first scenario.

  • When should I log out the test user?
    • Before each scenario?
    • After each scenario?
  • Can specflow and selenium drop state after each scenario?
  • Must I call page.Logout() every time?
Was it helpful?

Solution

I would say that you should log out, when it's relevant to the test case. Say you log in to SO and test posting a new question, then write an answer and add two comments to each. Logging in and out between each step would be a big hassle and no user would do that in the real world. Thus just log in at the start of the test scenario and log out when you're finished with it.

Another example would be doing each of the above steps as different users, then it would be a necessity to log in/log out at every step.

This applies in the bigger picture as well, if you have multiple scenarios that require a logged in user, but don't depend on any of that user's information, may as well just log in once before running all of them and then log out.

Specflow and Selenium don't hold the state, it's the system you're testing that does it. For instance if your session is stored in cookies, you could clear said cookies and that would in effect log you out. But this is not testing the system as the end user is meant to use it, so it's just cutting corners and testing different area of system (authorization of unauthenticated users) and thus doesn't really correlate very well to the real world case. Just use the log out button/link on the page, since you're writing browser based tests.

OTHER TIPS

I think you should make your test feature wise or module wise.
  • if you consider all the processes in a feature and according to the flow, you will only need to logout in the end.

  • If you make module wise, after a process you can logout each time and login again at the new module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top