Skip to content

Instantly share code, notes, and snippets.

@gasparrobi
Last active December 16, 2017 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gasparrobi/94de9a7036215e59afb395fb22064549 to your computer and use it in GitHub Desktop.
Save gasparrobi/94de9a7036215e59afb395fb22064549 to your computer and use it in GitHub Desktop.
Protractor clean code and practical tips from the official documentation

async/await

  • Don’t forget to turn off control_flow, you cannot use a mix of async/await and the control flow: async/await causes the control flow to become unreliable. So if you async/await anywhere in a spec, you should set the SELENIUM_PROMISE_MANAGER: false
  • Note: To write and run native async/await test, the node.js version should be greater than or equal to 8.0, and Jasmine version should be greater than or equal to 2.7

NEVER use xpath

  • It's the slowest and most brittle locator strategy of all
  • Markup is very easily subject to change and therefore xpath locators require a lot of maintenance
  • xpath expressions are unreadable and very hard to debug

Prefer by.model, by.binding, by.id, by.css

  • They are very performant and readable locators
  • Access elements easier
/* recommended */

let nameElement = element(by.binding('color.name'));
let personName = element(by.model('person.name'));
let elementById = element(by.id('myId'));
let elementByCss = element(by.css('.myclass'));

/* by.css() === $() */
let navButton = element($('#myNavButton'));

Use Page Objects to interact with page under test

  • Encapsulate information about the elements on the page under test
  • They can be reused across multiple tests
  • Decouple the test logic from implementation details
// TODO

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment