5. Differently of unit tests,
the main intention of UI
tests (e2e tests) is to save
time when running regression
tests, that are very slow and
boring to execute manually
30. ● General rules
● Project structure
● Locators strategy
● Page Objects
● Test suites
Style guide
31. ● Why?
○ Easy to locate tests
○ Separate e2e tests from unit tests
○ Cleaner test structure
Group e2e tests in a structure that make sense for the
whole project (ex.: my-project/tests/e2e/)
32.
33. ● General rules
● Project structure
● Locators strategy
● Page Objects
● Test suites
Style guide
34. ● Why?
○ Markup is easily subject to change
○ xpath has performance issues
○ xpath is not easily readable
NEVER use xpath
35.
36. ● Why?
○ Access elements easily
○ The code is harder to change than the
markup
○ More readable locators (e.g.: by.model,
by.binding, by.repeater)
Prefer Protractor specific locators when possible
37.
38. ● Why?
○ Access elements easily
○ This way you use markup that is less
subject to change
○ Readability
Prefer by.id and by.css when there is not Protractor
specific locator available
39.
40. Avoid text locators that change frequently
● Why?
○ Texts of buttons, links and labels tend
to change during the time
○ Tests will break after simple changes in
the texts
○ Localization
41. ● General rules
● Project structure
● Locators strategy
● Page Objects
● Test suites
Style guide
42. ● Why?
○ Encapsulation of elements from the page
under test
○ Code reuse
○ Decoupling test logic from
implementation details
Use Page Objects to interact with the page under test
43.
44. ● Why?
○ Maintain the code clean and ease finding
what you are looking for
Declare one Page Object per file
45.
46. Use just one module.exports at the end of the Page
Object
● Why?
○ One PageObject per file means that there
is only one class to export
47.
48. Require and instantiate all node modules in the top of
● Why?
○ The dependencies and node modules must be
clear and easy to find
○ Separations of dependencies and test code
○ Dependencies are then available for all the
test suite
49.
50. ● Why?
○ The user of the Page Object must have
quick access the the elements available
in the page
Declare all elements from the constructor as public
51.
52. Declare functions for operations that require more than
one step
● Why?
○ Clean code / Readability
○ Code reuse
○ Maintainability
53.
54. ● Why?
○ Tests are responsible for the assertions
○ People that will read the tests must be able
to understand the application expected
behaviour by just reading the tests
Don't do assertions in the Page Objects
55. ● Why?
○ You may reuse them in many tests
○ Avoid code duplicity
○ When a directive change, you just the to
change the wrapper, and only once
Add wrappers for directives, dialogs and common
elements
56.
57. ● General rules
● Project structure
● Locators strategy
● Page Objects
● Test suites
Style guide
58. ● Why?
○ E2e tests exist to simulate real users
using the application with all its
integrations
○ Using the real application with its own
dependencies provides high confidence
Do not use mock unless this is totally necessary
59. ● Why?
○ It is well documented
○ It is also supported by the Protractor team
○ beforeAll e afterAll
Use Jasmine2
60.
61. ● Why?
○ Run tests in parallel with sharding
○ The execution order is not guaranteed
○ You can run a test suite isolated
Make tests independent at least at the file level
62.
63. ● Why?
○ You may execute test cases isolated
○ Easy to debug (e.g.: fit, xit)
Make tests totally independent of each other
64. Except when the operations to start the test are
too much expensive
● Why?
○ The tests would be running for ever
Make tests totally independent of each other
65. ● Why?
○ Ensure that the main application parts
are well connected to each other
○ Real users don't navigate by URLs
Have a test suite to navigate through the main
application routes
66. ● Why?
○ Ensure that the tests is in a clean state
○ Avoid code duplicity
Navigate till the page under test before each test