Skip to content

Latest commit

 

History

History
43 lines (27 loc) · 2.83 KB

File metadata and controls

43 lines (27 loc) · 2.83 KB

Tips for Testing in FarmData2

THIS IS DRAFT AND NEEDS TO BE REVISED

The following bullet points provide some helpful tips for testing entry points:

  • Tests can output messages to the console using the cy.task command.
    • Use cy.task('log', 'message') to log text messages.
    • Use: cy.task('logObject', obj) to log an object to the console.

Best practice is to reset the database state before tests are run. Doing this before every test or even at the start of every file adds significantly to the runtime of the test suite. FarmData2 compromises by resetting the database to the DB that was most recently installed (i.e. using installDB.bash) before each test run. A test run is one cypress command (e.g. as is done by test.bash --comp). Any test that absolutely requires a clean database (i.e. cannot tolerate changes made by prior tests) can reset it in its before hook using the following code:

  before(() => {
    cy.task('initDB');
  });

You can change the database that will be used for testing by using the installDB.bash script manually prior to running the tests. This is useful when you want to run tests against a pre-release of the sample database. For example:

installDB.bash --release=v3.1.0-development.3 --asset=db.sample.tar.gz
  • Any it with an intercept should include { retries: 4 } to tolerate some of the flake that appears to go with cy.intercept.

  • clear() fields with content before type()ing in them

  • blur() any field that was type()d in or clear()ed before doing a submit or relying on its value. If changing lots of fields, then only need to blur the last one.

  • When setting or checking the value of a selector or numeric input be sure to get the element from the sub-component (e.g. selector-input or numeric-input). Some methods work on the parent component, but others do not. So, it is always safest to work with the *-input element itself.

  • If a contained data-cy is unique to a page just use it. cy.getting the parent element and using find may not work. Very strange behavior.

  • To use select() on a component built on top of the SelectorBase component, you must use cy.get(<component>).find('selector-input').select(<item>)

Note: Every test it should wait for the ready event to be emitted before performing any tests. In some components this will be immediately, in others it will wait for an API call to complete. This is included in all tests for consistency and to reduce test flake.

Use: cy.task('log', 'message') to log messages to the console. Use: cy.task('logObject', obj) to log an object to the console.

  • Visible in the console when running headless.
  • Click on the task in the test events output to print to console in Cypress gui.