Skip to content

Latest commit

 

History

History

fundamentals__dynamic-tests

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Dynamic tests

Sometimes you want to iterate through a list of items, and for each item create a separate test. These tests are called dynamic tests. Examples of dynamic tests are:

  • run same test against different viewport resolutions
  • run same test against different sub-domains of your site
  • generate tests based on the fetched data
  • get the dynamic data from the setupNodeEvents function before the tests start

Note

Sometimes the data to generate tests might be dynamic and come from an external source. You cannot ask for this kind of data from the test itself or from before hook, since it is too late. There are several workarounds:

  1. you can fetch data using a script that runs before Cypress starts. Save the results as a JSON file and load data using require. This has an advantage that the data does not change while running the tests, making debugging simpler. See suite called "generated from fixture" for an example.
  2. you can fetch the dynamic data before the tests and save as a local variable or context property, then have multiple tests assert against dynamic data items.
  3. you can get the data to use to create dynamic tests using cy.task
  4. you can get the data during the setupNodeEvents function start and place the result into Cypress.env() object to pass to the specs

Examples

In these repo you can find:

Cypress env object with fetched users