Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
TestCafe is an end-to-end testing framework for web applications. It allows you to write tests in JavaScript or TypeScript, run them across multiple browsers, and provides a rich set of features for automating user interactions and verifying application behavior.
Cross-browser Testing
TestCafe allows you to run tests across multiple browsers simultaneously. This code sample demonstrates how to set up TestCafe to run tests in both Chrome and Firefox.
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src('tests/test.js')
.browsers(['chrome', 'firefox'])
.run();
})
.then(failedCount => {
console.log('Tests failed: ' + failedCount);
testcafe.close();
});
Assertions
TestCafe provides a rich set of assertions to verify the state of your application. This code sample demonstrates how to use assertions to check that the text of an element matches the expected value.
import { Selector } from 'testcafe';
fixture `Getting Started`
.page `http://devexpress.github.io/testcafe/example`;
const developerNameInput = Selector('#developer-name');
const submitButton = Selector('#submit-button');
const articleHeader = Selector('#article-header');
test('My first test', async t => {
await t
.typeText(developerNameInput, 'John Smith')
.click(submitButton)
.expect(articleHeader.innerText).eql('Thank you, John Smith!');
});
Screenshots and Video Recording
TestCafe allows you to take screenshots and record videos of your tests. This code sample demonstrates how to take a screenshot after performing some actions.
import { Selector } from 'testcafe';
fixture `Screenshot and Video`
.page `http://devexpress.github.io/testcafe/example`;
const developerNameInput = Selector('#developer-name');
const submitButton = Selector('#submit-button');
test('Take a screenshot', async t => {
await t
.typeText(developerNameInput, 'John Smith')
.click(submitButton)
.takeScreenshot();
});
Parallel Test Execution
TestCafe supports parallel test execution to speed up the testing process. This code sample demonstrates how to run tests in parallel with a concurrency factor of 3.
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src('tests/test.js')
.browsers(['chrome', 'firefox'])
.concurrency(3)
.run();
})
.then(failedCount => {
console.log('Tests failed: ' + failedCount);
testcafe.close();
});
Cypress is a front-end testing tool built for the modern web. It offers a rich, interactive UI and a powerful API for writing tests. Compared to TestCafe, Cypress provides a more interactive debugging experience but is limited to running tests in Chrome and Electron.
Selenium WebDriver is a widely-used tool for automating web browsers. It supports multiple programming languages and browsers. Compared to TestCafe, Selenium WebDriver offers more flexibility and control but requires more setup and configuration.
Puppeteer is a Node library that provides a high-level API to control Chrome or Chromium over the DevTools Protocol. It is great for automating browser tasks and scraping. Compared to TestCafe, Puppeteer is more low-level and requires more boilerplate code for writing tests.
A Node.js tool to automate end-to-end web testing.
Write tests in JS or TypeScript, run them and view results.
Homepage • Documentation • FAQ • Support
npm install -g testcafe
Running a sample test in Safari
Stable tests and no manual timeouts
TestCafe automatically waits for page loads and XHRs before the test starts and after each action.
It also features smart test actions and assertions that wait for page elements to appear.
You can change the maximum wait time.
If elements load faster, tests skip the timeout and continue.
Rapid test development tool
Changes in test code immediately restart the test, and you see the results instantly.
See how it works in the TestCafe Live repository.
Latest JS and TypeScript support
TestCafe supports the latest JavaScript features, including ES2017 (for example, async/await).
You can also use TypeScript
if you prefer a strongly typed language.
Detects JS errors in your code
TestCafe reports JS errors that it finds on the webpage.
Tests automatically fail because of that.
However, you can disable this.
Concurrent test launch
TestCafe can open multiple instances of the same browser to run parallel
tests which decreases test execution time.
PageObject pattern support
The TestCafe's Test API
includes a high-level selector library, assertions, etc.
You can combine them to implement readable tests with the PageObject pattern.
const macOSInput = Selector('.column').find('label').withText('MacOS').child('input');
Easy to include in a continuous integration system
You can run TestCafe from a console, and its reports can be viewed in a CI system's interface
(TeamCity, Jenkins, Travis & etc.)
TestCafe works great for JavaScript developers, but at some point you will need to delegate testing tasks to your Q&A department. If that's the case and you are looking for a codeless way to record and maintain tests compatible with your existing infrastructure, check out TestCafe Studio - a testing IDE built on top of the open-source TestCafe.
Read the following article to learn how TestCafe Studio could fit into your workflow: What's Better than TestCafe? TestCafe Studio.
Record and Run a Test in TestCafe Studio
Ensure that Node.js (Current or Active LTS is recommended, version 12 at minimum) and npm are installed on your computer before running it:
npm install -g testcafe
As an example, we are going to test the https://devexpress.github.io/testcafe/example page.
Create a .js
or .ts
file on your computer.
Note that it needs to have a specific structure: tests must be organized into fixtures.
You can paste the following code to see the test in action:
import { Selector } from 'testcafe'; // first import testcafe selectors
fixture `Getting Started`// declare the fixture
.page `https://devexpress.github.io/testcafe/example`; // specify the start page
//then create a test and place your code there
test('My first test', async t => {
await t
.typeText('#developer-name', 'John Smith')
.click('#submit-button')
// Use the assertion to check if the actual header text is equal to the expected one
.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');
});
Call the following command in a command shell. Specify the target browser and file path.
testcafe chrome test1.js
TestCafe opens the browser and starts executing the test.
Important! Make sure the browser tab that runs tests stays active. Do not minimize the browser window. Inactive tabs and minimized browser windows switch to a lower resource consumption mode where tests are not guaranteed to execute correctly.
TestCafe outputs the results into a command shell by default. See Reporters for more information. You can also use plugins to customize the reports.
Read the Getting Started page for a more detailed guide.
Go to our website for full documentation on TestCafe.
Join the TestCafe community on Stack Overflow to get help. Ask and answer questions with the TestCafe tag.
Use our GitHub issues page to report bugs and suggest improvements.
Follow us on Twitter. We post TestCafe news and updates, several times a week.
Read our Contributing Guide to learn how to contribute to the project.
To create your own plugin for TestCafe, you can use these plugin generators:
If you want your plugin to be listed below, send us a note in a Github issue.
Thank you to all the people who already contributed to TestCafe!
aha-oretama | ai | aleks-pro | Aleksey28 | AlexanderMoiseev | AlexanderMoskovkin |
alexey-lin | AlexKamaev | alexphilin | AlexSkorkin | alexwybraniec | AnastasiaIvanova8 |
andrewbranch | AndreyBelym | AndyWendt | AnnaKondratova | anthophobiac | Artem-Babich |
Arthy000 | augustomezencio-hotmart | bdwain | benmonro | beyondcompute | bill-looby-i |
bsmithb2 | caseyWebb | cdrini | cgfarmer4 | Chris-Greaves | churkin |
dej611 | DIRECTcut | Dmitry-Ostashev | eignatyev | ericyd | Farfurix |
flora8984461 | GeoffreyBooth | helen-dikareva | honsq90 | infctr | inikulin |
Ivan-Katovich | jamesgeorge007 | jaypea | josephmalam | kanhaiya15 | karolnowinski |
kirovboris | kisrefod | LavrovArtem | link89 | lzxb | macdonaldr93 |
MargaritaLoseva | Marketionist | MatthewNielsen27 | mattkubej | mattmanske | mcjim |
miherlosev | morfey13 | mostlyfabulous | murajun1978 | NickCis | Nuarat |
Ogurecher | PayBas | pgorny | pietrovich | radarhere | raspo |
rbardini | renancouto | rob4629 | rueyaa332266 | sgrillon14 | smockle |
stefanschenk | superroma | sylbru | taiki-fw | testcafe-build-bot | theghostbel |
titerman | tobiasbueschel | varunkumar | VasilyStrelyaev | vitalics | Vla8islav |
wentwrong | b12031106 | danielroe | danieltroger | DevSide | intermike |
kirillsalikhov | michaelficarra | rr13k | tomashanacek | TrevorKarjanis |
TestCafe developers and community members made these plugins:
Browser Providers
Use TestCafe with cloud browser providers and emulators.
Framework-Specific Selectors
Work with page elements in a way that is native to your framework.
Plugins for Task Runners
Integrate TestCafe into your project's workflow.
Custom Reporters
View test results in different formats.
GitHub Action
Run TestCafe tests in GitHub Actions workflows.
Test Accessibility
Find accessibility issues in your web app.
IDE Plugins
Run tests and view results from your favorite IDE.
ESLint
Use ESLint when writing and editing TestCafe tests.
Cucumber Support
Create and run tests that use the Cucumber syntax.
TestCafe | TestCafe Studio | |
---|---|---|
No need for WebDriver, browser plugins or other tools | ✓ | ✓ |
Cross-platform and cross-browser out of the box | ✓ | ✓ |
Write tests in the latest JavaScript or TypeScript | ✓ | ✓ |
Clear and flexible API supports ES6 and PageModel pattern | ✓ | ✓ |
Stable tests due to the Smart Assertion Query Mechanism | ✓ | ✓ |
Tests run fast due to intelligent Automatic Waiting Mechanism and Concurrent Test Execution | ✓ | ✓ |
Custom reporter plugins | ✓ | ✓ |
Use third-party Node.js modules in test scripts | ✓ | ✓ |
Integration with popular CI systems | ✓ | ✓* |
Free and open-source | ✓ | |
Visual Test Recorder | ✓ | |
Interactive Test Editor | ✓ | |
Automatic Selector Generation | ✓ | |
Run Configuration Manager | ✓ | |
IDE-like GUI | ✓ |
* You can use open-source TestCafe to run TestCafe Studio tests in CI systems.
Show everyone you are using TestCafe:
To display this badge, add the following code to your repository readme:
<a href="https://github.com/DevExpress/testcafe">
<img alt="Tested with TestCafe" src="https://img.shields.io/badge/tested%20with-TestCafe-2fa4cf.svg">
</a>
We are grateful to BrowserStack for providing the infrastructure that we use to test code in this repository.
Code released under the MIT license.
Developer Express Inc. (https://devexpress.com)
FAQs
Automated browser testing for the modern web development stack.
We found that testcafe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.