UNPKG

4.01 kBMarkdownView Raw
1# cypress-failed-log
2
3> Gets you the Cypress test command log as JSON on failure
4
5[![NPM][npm-icon] ][npm-url]
6
7[![Build status][ci-image] ][ci-url]
8[![semantic-release][semantic-image] ][semantic-url]
9[![js-standard-style][standard-image]][standard-url]
10
11## Install
12
13Add this module as a dev dependency to your project
14
15```sh
16npm install --save-dev cypress-failed-log
17```
18
19Then include this module from your `cypress/support/index.js` file
20
21```js
22// cypress/support/index.js
23require('cypress-failed-log')
24```
25
26Add an NPM script `failed-test` that will get the name of the JSON file
27with failed test details.
28
29```json
30{
31 "scripts": {
32 "failed-test": "echo Test failed, details in $1"
33 }
34}
35```
36
37You can send the file as an email, upload it somewhere, post to a chat
38channel, etc.
39
40## JSON file fields
41
42The saved JSON file will have the following properties (see
43[src/index.js](src/index.js#L67))
44
45```
46title - the name of the test
47testName - full name of the test, including the suite name
48testError - error message string
49testCommands - array of strings, last failing command is last
50screenshot - filename of PNG file taken right after failure
51```
52
53## Example
54
55Here is the failed test JSON file contents. The test name, the failure
56and each test command before the test are recorded
57
58```json
59{
60 "title": "loads the About tab",
61 "testName": "Website loads the About tab",
62 "testError": "Timed out retrying: Expected to find content: 'Join Us' but never did.",
63 "testCommands": [
64 "visit",
65 "new url https://www.company.com/#/",
66 "contains a.nav-link, About",
67 "click",
68 "new url https://www.company.com/#/about",
69 "hash",
70 "assert expected **#/about** to equal **#/about**",
71 "contains Join Us",
72 "assert expected **body :not(script):contains(**'Join Us'**), [type='submit'][value~='Join Us']** to exist in the DOM"
73 ],
74 "screenshot": "opens-login.png"
75}
76```
77
78### Small print
79
80Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2017
81
82* [@bahmutov](https://twitter.com/bahmutov)
83* [glebbahmutov.com](http://glebbahmutov.com)
84* [blog](http://glebbahmutov.com/blog)
85
86License: MIT - do anything with the code, but don't blame me if it does not work.
87
88Support: if you find any problems with this module, email / tweet /
89[open issue](https://github.com/bahmutov/cypress-failed-log/issues) on Github
90
91## MIT License
92
93Copyright (c) 2017 Gleb Bahmutov <gleb.bahmutov@gmail.com>
94
95Permission is hereby granted, free of charge, to any person
96obtaining a copy of this software and associated documentation
97files (the "Software"), to deal in the Software without
98restriction, including without limitation the rights to use,
99copy, modify, merge, publish, distribute, sublicense, and/or sell
100copies of the Software, and to permit persons to whom the
101Software is furnished to do so, subject to the following
102conditions:
103
104The above copyright notice and this permission notice shall be
105included in all copies or substantial portions of the Software.
106
107THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
108EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
109OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
110NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
111HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
112WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
113FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
114OTHER DEALINGS IN THE SOFTWARE.
115
116[npm-icon]: https://nodei.co/npm/cypress-failed-log.svg?downloads=true
117[npm-url]: https://npmjs.org/package/cypress-failed-log
118[ci-image]: https://travis-ci.org/bahmutov/cypress-failed-log.svg?branch=master
119[ci-url]: https://travis-ci.org/bahmutov/cypress-failed-log
120[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
121[semantic-url]: https://github.com/semantic-release/semantic-release
122[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
123[standard-url]: http://standardjs.com/