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 |
|
13 | Add this module as a dev dependency to your project
|
14 |
|
15 | ```sh
|
16 | npm install --save-dev cypress-failed-log
|
17 | ```
|
18 |
|
19 | Then include this module from your `cypress/support/index.js` file
|
20 |
|
21 | ```js
|
22 | // cypress/support/index.js
|
23 | require('cypress-failed-log')
|
24 | ```
|
25 |
|
26 | Add an NPM script `failed-test` that will get the name of the JSON file
|
27 | with failed test details.
|
28 |
|
29 | ```json
|
30 | {
|
31 | "scripts": {
|
32 | "failed-test": "echo Test failed, details in $1"
|
33 | }
|
34 | }
|
35 | ```
|
36 |
|
37 | You can send the file as an email, upload it somewhere, post to a chat
|
38 | channel, etc.
|
39 |
|
40 | ## JSON file fields
|
41 |
|
42 | The saved JSON file will have the following properties (see
|
43 | [src/index.js](src/index.js#L67))
|
44 |
|
45 | ```
|
46 | title - the name of the test
|
47 | testName - full name of the test, including the suite name
|
48 | testError - error message string
|
49 | testCommands - array of strings, last failing command is last
|
50 | screenshot - filename of PNG file taken right after failure
|
51 | ```
|
52 |
|
53 | ## Example
|
54 |
|
55 | Here is the failed test JSON file contents. The test name, the failure
|
56 | and 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 |
|
80 | Author: 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 |
|
86 | License: MIT - do anything with the code, but don't blame me if it does not work.
|
87 |
|
88 | Support: 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 |
|
93 | Copyright (c) 2017 Gleb Bahmutov <gleb.bahmutov@gmail.com>
|
94 |
|
95 | Permission is hereby granted, free of charge, to any person
|
96 | obtaining a copy of this software and associated documentation
|
97 | files (the "Software"), to deal in the Software without
|
98 | restriction, including without limitation the rights to use,
|
99 | copy, modify, merge, publish, distribute, sublicense, and/or sell
|
100 | copies of the Software, and to permit persons to whom the
|
101 | Software is furnished to do so, subject to the following
|
102 | conditions:
|
103 |
|
104 | The above copyright notice and this permission notice shall be
|
105 | included in all copies or substantial portions of the Software.
|
106 |
|
107 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
108 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
109 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
110 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
111 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
112 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
113 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
114 | OTHER 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/
|