Giter Club home page Giter Club logo

grunt-testcafe's Introduction

grunt-testcafe

Build Status

Tests runner

Getting Started

This plugin requires Grunt 0.4 - 1.

npm install grunt-testcafe --save-dev

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks("grunt-testcafe")

The "testcafe" task

Overview

In your project's Gruntfile, add a section named testcafe to the data object passed into grunt.initConfig().

grunt.initConfig({
    testcafe: {
        test: {
            options: {
                files: ["tests/*.test.js"],
                browsers: ["chrome"]
            }
        }
    }
})

Advanced example:

grunt.initConfig({
    testcafe: {
        test: {
            options: {
                files: ["tests/*.test.js"],
                browsers: ["firefox", "chrome"],
                takeScreenshotsOnFail: true,
                screenshotsPath: "tests/screenshots",
                filter: (testName, fixtureName, fixturePath) => {
                    const testNameFilter = testName.match(
                        new RegExp(grunt.option("testName"))
                    )
                    const fixtureNameFilter = fixtureName.match(
                        new RegExp(grunt.option("fixtureName"))
                    )
                    const fixturePathFilter = fixturePath.match(
                        new RegExp(grunt.option("fixturePath"))
                    )
                    return (
                        testNameFilter && fixtureNameFilter && fixturePathFilter
                    )
                }
            }
        }
    }
})

Options

files

Type: Array

Default: []

Details: Configures the test runner to run tests from the specified files.

browsers

Type: Array

Default: []

Details: Specifying Browsers for Test Task

Configures the test runner to run tests in the specified browsers.

Required

concurrency

Type: Number

Default: 1

Details: Specifies that tests should run concurrently.

reporters

Type: Array

Default: ['spec']

Details: Reporters

Specifies the reporter. Output file can be passed along with reporter name by colon (:) separator. Example
reporters: ['json:report.json', 'xunit:report.xml']

filter

Type: function(testName, fixtureName, fixturePath)

Default: null

Details: runner.filter

Allows you to manually select which tests should be run.

screenshotsPath

Type: String

Default: null

Details: Screenshots path

The path to which the screenshots will be saved. Enables the test runner to take screenshots of the tested webpages.

screenshotsPathPattern

Type: String

Default: null

Details: Screenshots path pattern

Specifies a custom pattern to compose screenshot files' relative path and name. This pattern overrides the default path pattern.

takeScreenshotsOnFail

Type: Boolean

Default: false

Details: Take screenshots on fail

Specifies if screenshots should be taken automatically whenever a test fails. Requires that the screenshotsPath is set.

skipJsErrors

Type: Boolean

Default: false

Details: Skip JS errors

Defines whether to continue running a test after a JavaScript error occurs on a page (true), or consider such a test failed (false).

quarantineMode

Type: Boolean

Default: false

Defines whether to enable the quarantine mode.

selectorTimeout

Type: Number

Default: 10000

Details: Selector timeout

Specifies the amount of time, in milliseconds, within which selectors make attempts to obtain a node to be returned.

assertionTimeout

Type: Number

Default: 3000

Details: Assertion options

Specifies the amount of time, in milliseconds, within which TestCafe makes attempts to successfully execute an assertion if a selector property or a client function was passed as an actual value.

speed

Type: Number

Default: 1

Details : Speed factor

Specifies the speed of test execution. Should be a number between 1 (the fastest) and 0.01 (the slowest).

startApp

Type: Object { command, initDelay }

Default: { initDelay: 1000 }

Details : startApp

Specifies a shell command that will be executed before running tests. Use it to launch or deploy the application that will be tested.

proxyHost

Type: String

Default: null

Details : proxy

Specifies the proxy server used in your local network to access the Internet. You can also specify authentication credentials with the proxy host.

License

The MIT License

grunt-testcafe's People

Contributors

alexandermoskovkin avatar balajir avatar crudo avatar greenkeeperio-bot avatar kfern avatar lhorak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-testcafe's Issues

README.md provides a wrong example

Hi @crudo !

Thanks for your cool plugin.

But it seems that README.md provides a wrong example. The code doesn't work if I just copy-paste it.
However, it works if I write:

grunt.initConfig({
    testcafe: {
        'test-functional': {    // note this line
            options: {
                files:    ['tests/*.test.js'],
                browsers: ['chrome']
            }
        }
    }
});

Cannot find module 'mkdirp'

Hi.

Maybe it's a very basic thing and i'm just missing something, but can't make it run.
I have very simple test case and it runs perfectly when i run: testcafe chrome e2e/test.js

But when i try to run this grunt task:

testcafe: {
      test: {
        options: {
          files: ['e2e/*.js'],
          browsers: ['chrome'],
          takeScreenshotsOnFail: true,
          screenshotsPath: 'e2e/screenshots',
        }
      }
    }

I get error:
Loading "testcafe.js" tasks...ERROR Error: Cannot find module 'mkdirp'

What am i missing here? Should i install mkdirp as dev dependency?

node 4.7.2
testcafe 0.15.0 (tried both - global and local)
grunt 0.4.5
grunt-testcafe 0.15.0

edge issue

This may be redundant when Edge gets chrome engine but; I have the issue where I need to add the option "--hostname localhost" in order to run my tests in Edge. Is there a way to achieve this?

Add test run concurrency to list of available options

h2. Suggestion
Most TestCafe options are present in the grunt-testcafe package. One main thing that my team are missing are the ability to add test run concurrency to the grunt task.

h2. Expectation
Ideally, I'd like to be able to add the number of tests to run concurrently to the grunt testcafe options like:

        options: {
          files: ['tests/web/*.js'],
          browsers: ['chrome'],
          takeScreenshotsOnFail: true,
          screenshotsPath: 'output/screenshots',
          skipJsErrors: true,
          concurrency: 3,
          quarantineMode: true,
          reporter: 'minimal'
        }

Running process finishes successfully (with exit code 0) even if tests are failed

Hi @crudo ,

I've found that the grunt task finished successfully (with exit code 0) even if the testcafe tests are failed. It's not usable for CI. For example on Travis, if the test task process is finished with exit code 0 - the test is green, otherwise - it's failed. With the current version of grunt-testcafe my CI test task is always green, even tests are failed (example)

If you agree I can create a pull-request with the fix. But in this case what I should do with the tests in the repository.
Maybe split your tests into two parts?

grunt.registerTask('test-locally', ['http-server', 'testcafe', 'clean:test']);
grunt.registerTask('test-ci', ['http-server', 'testcafe:form', 'clean:test'])

outdated peer-dependency

there is a peerDependency listed in package.json of "testcafe": "< 0.19.0" while devDependencies lists "testcafe": "0.21.1",. This makes npm error on an install and causes jenkins to fail unless I hide all potential serious errormessages

Feature Request: Add screenshot path pattern

Request Rationale

From TestCafe v0.21.0, you can specify a custom pattern to compose files' relative path and name. Having the ability to set this when running tests from Grunt would be advantagous.

Steps

I don't have access to create branches or PRs but I believe this would be the steps to do it:

Upgrade the referenced version of Testcafe in the package.json file to v0.21.0

File tasks/testcafe.js update DEFAULT_OPTS to:
(starting line 16)

const DEFAULT_OPTS = {
    assertionTimeout: 3000,
    browsers: [],
    concurrency: 1,
    filter: null,
    quarantineMode: false,
    reporter: 'spec',
    screenshotsPath: null,
    screenshotPathPattern: null,
    selectorTimeout: 10000,
    skipJsErrors: false,
    speed: 1,
    startApp: { initDelay: 1000 },
    takeScreenshotsOnFail: false,
    proxyHost: null
};

and update the following (starting line 67) to:

                return testCafeRunner
                    .useProxy(opts.proxyHost)
                    .src(files)
                    .browsers(opts.browsers)
                    .concurrency(opts.concurrency)
                    .filter(opts.filter)
                    .screenshots(opts.screenshotsPath, opts.takeScreenshotsOnFail, opts.screenshotPathPattern)
                    .reporter(opts.reporter, stream)
                    .run(opts);

Update the readme with

#### screenshotsPathPattern

*Type*: `String`

*Default*: `null`

*Details*: [Screenshots path pattern](https://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#-p---screenshot-path-pattern)

Specifies a custom pattern to compose screenshot files' relative path and name. This pattern overrides the default path pattern.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.