Selenium Python run multiple test cases how do i log in once and use the same instance browser

后端 未结 1 1252
名媛妹妹
名媛妹妹 2020-12-11 08:31

I have created some Test Cases in Selenium Python and I have put it in a Test Suite. Each time a Test Case runs it opens the browser and navigates to the URL. It then logs

相关标签:
1条回答
  • 2020-12-11 09:24

    Slow automated tests caused by needlessly opening and closing browsers, hardcoded delays etc. are, as you say, a huge waste of time, and almost always avoidable in my experience.

    The good news is that you don't need to do anything special to avoid this. If your tests are independent and run in sequence, also assuming that you only have one browser/version and set of Capabilities, then all your test runner needs to do is:

    • create singleton Driver at start of run (or application, if multiple runs allowed; or lazily when first required)
    • run each test in sequence, with no explicit close or quit calls, but with all other suitable cleanup (clearing any created cookies, logging out, clearing sessions, Local storage etc.)
    • quit Driver at the (very) end

    It's not very much more work to support multiple browsers / capabilities in much the same way.

    0 讨论(0)
提交回复
热议问题