Examples

This section lists examples from the testcafe-examples repository. All examples are ready to run.

Locating Elements

Example Description
Find Element By Trimmed Text Ignores white-space characters when searching for an element by text.
Use XPath Selectors Find an input with an XPath selector.

Testing the DOM

Example Description
Access Element Properties Access DOM element properties and verify them with assertions.
Iterate Over Table Rows Verify cell content for even and odd rows.
Test <select> Elements Open a <select> element's drop-down list, click an item, and verify the value.
Page Reload Execute custom code on the page to obtain data or manipulate the page state.

Test Organization

Example Description
Extract Code to Helpers Extract test code to functions defined in a separate module.
Create Data-Driven Tests Create a test that performs parameterized actions.
Use Page Model Extract element selectors and common operations with these elements to a page model.

Interoperability

Example Description
Inject Custom Client Scripts Inject Node.js modules into the tested webpage.
Import Third-Party Modules Import a third-party Node.js module into test code.

Browser API Mocks

Example Description
Mock Date Substitutes current data with mockdate.
Mock Geolocation API Substitutes the current location with a mock location.

Wait Mechanisms

Example Description
Wait Until an Element Property Has a Specific Value Use an assertion to pause the test until an element's width is 100%.
Wait For File Download Specify that the test should wait for the file to download.