This repository contains sample test files that help you learn how to use TestCafe.
Here you will find examples that demonstrate the basic usage, advanced features, edge cases, as well as tips and tricks.
-
Clone this repository:
git clone https://github.com/DevExpress/testcafe-examples.git
-
Go to the project's root directory:
cd testcafe-examples
-
Install the dependencies:
npm install
Use the npm test
script to run all tests in Chrome and Firefox.
npm test
You can use TestCafe CLI options to specify different target browsers or run tests from a specific directory.
To run tests in Chrome only, execute the following command:
npx testcafe chrome examples
The following command runs the examples from the client-scripts
directory:
npx testcafe chrome examples/client-scripts
See Command Line Interface for more information.
We are in the process of adding more examples to this repository.
The repository includes the following examples:
- Access Element Properties
- Change Element's Style
- Check If an Image Has Loaded
- Check the Downloaded File Name and Content
- Check Whether Web Page Is Opened With TestCafe
- Create Data-Driven Tests
- Extract Reused Code to Helper Functions
- Find Element By Trimmed Text
- Import Third-Party Modules
- Inject Custom Client Scripts
- Iterate Over a List of Elements
- Iterate Over Table Rows
- Mock Date
- Mock Geolocation API
- Page Manipulation
- Pass Parameters to Tests
- Scroll Elements Into View
- Select a Table Row by Cell Content
- Select Files To Upload
- Set a Custom Referrer
- Simulate the Web Page Losing Focus
- Submit a Form
- Test <select> Elements
- Use Page Model
- Use XPath Selectors
- Wait Until an Element Property Has a Specific Value
- Wait For File Download
Below are the examples that run in Chrome or Firefox only or require additional launch arguments. You should launch these examples separately.