selenium-Avoid sharing state


title: “Avoid sharing state”
weight: 6

Although mentioned in several places it is worth mentioning again. Ensure
tests are isolated from one another.

  • Do not share test data. Imagine several tests that each query the database
    for valid orders before picking one to perform an action on. Should two tests
    pick up the same order you are likely to get unexpected behaviour.

  • Clean up stale data in the application that might be picked up by another
    test e.g. invalid order records.

  • Create a new WebDriver instance per test. This helps ensure test isolation
    and makes parallelization simpler.

官方链接为:/documentation/test_practices/encouraged/avoid_sharing_state/