JavaScript HTML TypeScript Other
Latest commit ccd4b1f Jul 25, 2017 @AlexanderMoskovkin AlexanderMoskovkin committed on GitHub Avoid waiting for a fixed element (follow up #1521) (#1646)
* Avoid waiting for a fixed element (follow up #1521)

* Fix `clientPositionChangedAfterMoving` calculation
Permalink
Failed to load latest commit information.
.github [docs] Added a contribution guide, code of conduct and issue template… Oct 12, 2016
.md-lint [docs] Recipe - Remote and Mobile (#1103) Dec 28, 2016
bin Use V8 flag filters only in CLI. Helps avoid confusion when bin/testc… Mar 23, 2017
docker Fix screenshots on Docker (closes #1540) (#1563) Jun 26, 2017
docs [docs] Add remarks about meta and alt keys (#1638) Jul 24, 2017
examples fix link err (#1526) Jun 11, 2017
media [docs] Fix client debugging example (#1363) Mar 28, 2017
src Avoid waiting for a fixed element (follow up #1521) (#1646) Jul 25, 2017
test Avoid waiting for a fixed element (follow up #1521) (#1646) Jul 25, 2017
ts-defs Fix typo in TS defs (closes #1541) (#1542) Jun 19, 2017
.dockerignore Implement builds of Docker images (closes #1141) (#1197) Apr 11, 2017
.editorconfig Start implementing build infrastructure Jun 25, 2015
.eslintignore Fix `ReferenceError: selector is not defined` if selector promise is … Aug 12, 2016
.eslintrc Add import/export eslint rules (#741) Aug 30, 2016
.gitattributes Implement builds of Docker images (closes #1141) (#1197) Apr 11, 2017
.gitignore Bump to release version (#1365) Mar 28, 2017
.publishrc Bump version (#1588) Jul 5, 2017
.travis-docs.yml [docs] Add info about Chrome-specific features (#1513) Jun 13, 2017
.travis.yml [WIP ]try to stable osx tests (#1566) Jun 28, 2017
CHANGELOG.md [docs] Add a changelog for v0.16.2 (#1572) Jun 27, 2017
CODE_OF_CONDUCT.md Update CODE_OF_CONDUCT.md Jun 19, 2017
CONTRIBUTING.md A couple of corrections (#895) Oct 19, 2016
Gulpfile.js Workaround for gulp-git on node 8 (#1506) May 31, 2017
LICENSE Update year in license Jan 16, 2017
README.md Fix a broken link Jun 27, 2017
appveyor.yml Should hide Shadow-UI root for get elementFromPoint in iframe in IE (… Dec 13, 2016
package.json Bump version (alpha) (#1643) Jul 24, 2017

README.md

testcafe

https://devexpress.github.io/testcafe

Automated browser testing for the modern web development stack.

Functional Windows desktop All Travis tasks (server, client, functional: mobile, macOS, Edge) NPM Version


TestCafe is a pure node.js end-to-end solution for testing web apps. It takes care of all the stages: starting browsers, running tests, gathering test results and generating reports. TestCafe doesn’t need browser plugins - it works in all popular modern browsers out-of-the-box.

Install TestCafe and Run a Test

Features

Easy Install

Everything is included in a single module installed with one command.

npm install -g testcafe

No native parts to compile, no browsers plugins to install.

Complete Test Harness

TestCafe automatically starts browsers, runs tests and gathers results. You only type a single command to begin testing.

testcafe chrome tests/

When testing is finished, TestCafe aggregates test results from different browsers and outputs them into one comprehensive report.

Write Test Code in Modern JavaScript and TypeScript

TestCafe allows you to write tests using TypeScript or JavaScript (with its modern features like async/await).

Test API consists of over two dozen methods that can emulate all actions one could possibly do with a webpage. Chained syntax allows for code that is easy to write and read.

fixture `Example page`
    .page `https://devexpress.github.io/testcafe/example`;

test('Emulate user actions and perform a verification', async t => {
    await t
        .setNativeDialogHandler(() => true)
        .click('#populate')
        .click('#submit-button');

    const location = await t.eval(() => window.location);

    await t.expect(location.pathname).eql('/testcafe/example/thank-you.html');
});

By using TypeScript to write your TestCafe tests, you get the advantages of strongly-typed languages such as: rich coding assistance, painless scalability, check-as-you-type code verification, and much more.

To make debugging easier, TestCafe automatically generates source maps. To debug your test code, start a debugging session in an IDE that supports source maps.

Flexible Selector System

TestCafe supports a flexible selector system that provides API with rich capabilities for writing test scripts. You can access webpage elements in different ways using selectors. For example, you can use one of the following selector types:

  • CSS selector
  • Text
  • DOM hierarchy
  • or use any custom logic

The selector API provides methods that can be combined together, thus providing you with a flexible functional-style selector mechanism.

const macOSInput = Selector('.column').find('label').withText('MacOS').child('input');

Check our example that demonstrates how to create tests using declarative Page Objects built with TestCafe selectors.

Smart assertions

TestCafe provides a full-featured set of built-in assertions, so you do not need to reference additional libraries. Use assertions with Selector's DOM node state properties to enable the Smart Assertion Query Mechanism and create stable, fast and reliable tests that do not depend on page response time.

import { Selector } from 'testcafe';

fixture `Example page`
    .page `http://devexpress.github.io/testcafe/example/`;

test('Check property of element', async t => {
    const developerNameInput = Selector('#developer-name');

    await t
        .expect(developerNameInput.value).eql('', 'input is empty')
        .typeText(developerNameInput, 'Peter Parker')
        .expect(developerNameInput.value).contains('Peter', 'input contains text "Peter"');
});

No Extra Coding

Write tests without boilerplate code.

  • TestCafe automatically waits for page loads and XHRs to complete, as well as for DOM elements to become visible. You do not need to write custom code for that.
  • Test runs are isolated, which means that they do not share cookies, local or session storages. There is nothing to clean up between test runs.

Descriptive Reports

TestCafe automatically generates full-detailed reports that provide a test run summary and comprehensive information about errors. Automatic page screenshots, fancy call sites and call stacks free of TestCafe internals allow you to easily detect error causes.

Use one of built-in reporters to output test results or create your own one to produce custom reports.

Spec Report

Straightforward Continuous Integration

TestCafe is easy to set up on popular Continuous Integration platforms as it allows you to test against various browsers: local, remote, cloud (e.g., Sauce Labs) or headless (e.g. Nightmare). You can also create a custom browser provider to add support for a browser or a cloud platform of your choice.

Other Useful Features

Getting Started

Installing TestCafe

Ensure that Node.js and npm are installed on your computer, then run a single command:

npm install -g testcafe

For more information, see Installing TestCafe.

Creating a Test

TestCafe allows you to write tests using TypeScript or JavaScript (with its modern features like async/await). By using TypeScript to write your TestCafe tests, you get the advantages of strongly-typed languages such as: rich coding assistance, painless scalability, check-as-you-type code verification, and much more. For more information about writing tests in TypeScript, see TypeScript Support.

To create a test, create a new .js or .ts file anywhere on your computer. This file must have a special structure: tests must be organized into fixtures.

Firstly, import the testcafe module.

import { Selector } from 'testcafe';

Then declare a fixture using the fixture function.

fixture `Getting Started`

In this tutorial, you will create a test for the https://devexpress.github.io/testcafe/example sample page. Specify this page as a start page for the fixture by using the page function.

fixture `Getting Started`
    .page `https://devexpress.github.io/testcafe/example`;

Then, create the test function where you will place test code.

import { Selector } from 'testcafe';

fixture `Getting Started`
    .page `https://devexpress.github.io/testcafe/example`;

test('My first test', async t => {
    // Test code
});

Running the Test

You can simply run the test from a command shell by calling a single command where you specify the target browser and file path.

testcafe chrome test1.js

TestCafe will automatically open the chosen browser and start test execution within it.

Important! Make sure to keep the browser tab that is running tests 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.

For more information on how to configure the test run, see Command Line Interface.

Viewing the Test Results

While the test is running, TestCafe is gathering information about the test run and outputting the report right into a command shell.

Test Report

For more information, see Reporters.

Writing Test Code

Performing Actions on the Page

Every test should be capable of interacting with page content. To perform user actions, TestCafe provides a number of actions: click, hover, typeText, setFilesToUpload, etc. They can be called in a chain.

The following fixture contains a simple test that types a developer name into a text editor and then clicks the Submit button.

import { Selector } from 'testcafe';

fixture `Getting Started`
    .page `https://devexpress.github.io/testcafe/example`;

test('My first test', async t => {
    await t
        .typeText('#developer-name', 'John Smith')
        .click('#submit-button');
});

All test actions are implemented as async functions of the test controller object t. This object is used to access test run API. To wait for actions to complete, use the await keyword when calling these actions or action chains.

Observing Page State

TestCafe allows you to observe the page state. For this purpose, it offers special kinds of functions that will execute your code on the client: Selector used to get direct access to DOM elements and ClientFunction used to obtain arbitrary data from the client side. You call these functions as regular async functions, that is you can obtain their results and use parameters to pass data to them.

The selector API provides methods and properties to select elements on the page and get theirs state.

For example, clicking the Submit button on the sample web page opens a "Thank you" page. To get access to DOM elements on the opened page, the Selector function can be used. The following example demonstrates how to access the article header element and obtain its actual text.

import { Selector } from 'testcafe';

fixture `Getting Started`
    .page `http://devexpress.github.io/testcafe/example`;

test('My first test', async t => {
    await t
        .typeText('#developer-name', 'John Smith')
        .click('#submit-button');

    const articleHeader = await Selector('.result-content').find('h1');

    // Obtain the text of the article header
    let headerText = await articleHeader.innerText;
});

For more information, see Selecting Page Elements.

Assertions

A functional test also should check the result of actions performed. For example, the article header on the "Thank you" page should address a user by the entered name. To check if the header is correct, you have to add an assertion to the test.

The following test demonstrates how to use build-in assertions.

import { Selector } from 'testcafe';

fixture `Getting Started`
    .page('https://devexpress.github.io/testcafe/example');

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!');
});

Documentation

TestCafe Ecosystem

The following plugins make your work with TestCafe easy and introduce new features.

IDE Plugins

Run tests and view test results right from your favorite IDE.

Framework-Specific Selectors

Work with page elements in a way that is native to your framework.

Plugins for Task Runners

Easily integrate TestCafe into your project's workflow.

Browser Providers

Provide support for more browsers to test against.

Custom Reporters

Enable TestCafe to present test results in different formats.

ESLint

Use ESLint when writing and editing TestCafe tests.

Accessibility

Find accessibility issues in your web app.

Thanks to BrowserStack

We are grateful to BrowserStack for providing infrastructure that we use to test code in this repository.

BrowserStack Logo

Roadmap

We plan to introduce other outstanding features so that you can test apps with even more efficiency. Meanwhile, you can help us improve TestCafe by voting for features on our roadmap.

Contributing

Please use our issues page to report a bug or request a feature.

For general purpose questions and discussions, use the discussion board.

For more information on how to help us improve TestCafe, please see the CONTRIBUTING.md file.

Stay in Touch

License

MIT

Author

Developer Express Inc. (https://devexpress.com)