What are some best practices for structuring e2e t

2019-07-05 09:33发布

问题:

I'm a bit confused as to the best way to structure end to end tests.

Most tests tests that I write depend on other tests.

i.e

  • User needs to log in
  • User needs to create Foo
  • User can now create Bar
  • Bar needs to exist, in order to edit it obviously.

How would you structure your tests to take this into account?

回答1:

I would personally make use of the PageObject pattern, this will allow reliability and make the code more maintainable in these situations. Once you have that in place you can then create different methods in your PageObject classes that act upon those pages. E.g.

LoginPage would be a class using the PageObject pattern and would contain methods like LogIn() which would return the type of HomePage, which would be another class using the PageObject pattern.

I have not used Selenium to preform E2E tests on an application since I don't think the tool is designed for that.

Really what you want is a tool to preform BDD (Behaviour Driven Development).

The way I would structure your scenario that is in your post is that I would have separate tests for each one. I'd have a Test to make sure I can log in successfully and unsuccessfully. I would then have another test that would create a user 'Foo', then would have a 'static' user ready to edit.