Kaustubh
Kaustubh

Reputation: 506

How to maintain session and WebDriver initialisation in while running multiple test cases

I have multiple test cases and I have multiple class files one for login, one for user creation and etc. Would it be possible to do like this - I wish to initialise the WebDriver once say in login test case and then wish to execute other test cases by maintaing the session and without re-initialising the WebDriver in further test cases. Is is possible?

Upvotes: 0

Views: 112

Answers (1)

Kovacic
Kovacic

Reputation: 1481

This is not good practice.

Try to avoid this at all cost. Every test should be modular and independent as possible.

Good thing is that You divided them logicaly, but don't go to re-use driver and session, this is just bad practice, and doesn't bring You nothing.

Good Practice:

  1. Use PageObjects Pattern
  2. keep your code robust and portable (Preferred selector order: id > name > css> xpath)
  3. Avoid Thread.sleep prefer Wait
  4. keep test as small as possible and Your code modular and re-usable

@murali provided example in his link, but as I mentioned this is not good practice.

Hope that this helps,

Upvotes: 1

Related Questions