Code Monkey home page Code Monkey logo

cypress-failed-log's Introduction

cypress-failed-log cypress version

Shows the commands from Cypress.io failed test in the terminal.

NPM

ci status semantic-release js-standard-style renovate-app badge

Install

Add this module as a dev dependency to your project

npm install --save-dev cypress cypress-failed-log
# if using Yarn
yarn add -D cypress-failed-log

Then include this module from your cypress/support/e2e.js file

// in your cypress/support/e2e.js
// or spec file
// https://github.com/bahmutov/cypress-failed-log
require('cypress-failed-log')
// you can use the "import" keyword
import "cypress-failed-log"

Recommended for v10

// cypress.config.js
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  defaultCommandTimeout: 500,
  e2e: {
    setupNodeEvents(on, config) {
      // https://github.com/bahmutov/cypress-failed-log
      require('cypress-failed-log/on')(on)
    },
  },
})

When Cypress runs, you will see commands including the failed one, right in the terminal

Failed terminal output

JSON file

In addition, all failed commands will be saved into a JSON file. The saved JSON file will live in cypress/logs/ and have the following properties:

specName - filename of the spec
title - the name of the test
suiteName - the parent suite name
testName - full name of the test, including the suite name
testError - error message string
testCommands - array of strings, the last failing command is the last item

Example

Here is the failed test JSON file contents. The test name, the failure and each test command before the test are recorded

{
  "specName": "failing-spec.js",
  "title": "loads the About tab",
  "suiteName": "Website",
  "testName": "Website loads the About tab",
  "testError": "Timed out retrying: Expected to find content: 'Join Us' but never did.",
  "testCommands": [
    "visit",
    "new url https://www.company.com/#/",
    "contains a.nav-link, About",
    "click",
    "new url https://www.company.com/#/about",
    "hash",
    "assert expected **#/about** to equal **#/about**",
    "contains Join Us",
    "assert expected **body :not(script):contains(**'Join Us'**), [type='submit'][value~='Join Us']** to exist in the DOM"
  ]
}

Debugging

To turn on debug messages in the browser, open in Cypress browser DevTools console and enter localStorage.debug = 'cypress-failed-log', then reload the spec. You should see log messages.

Small print

Author: Gleb Bahmutov <[email protected]> © 2017

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

MIT License

Copyright (c) 2017 Gleb Bahmutov <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cypress-failed-log's People

Contributors

bahmutov avatar c32hedge avatar greenkeeper[bot] avatar kristiehowboutdat avatar llatinov avatar masonm avatar rarkins avatar renovate-bot avatar renovate[bot] avatar shinobi64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cypress-failed-log's Issues

Why does cypress-failed-log need to take screenshots?

Since Cypress already takes screenshots on failed tests, the screenshot taken by cypress-failed-log seems redundant. In addition, I've seen some issues where the cypress-failed-log screenshot fails in certain cases, whereas the default screenshot doesn't. Is this an obsolete feature at this point?

TypeError: Converting circular structure to JSON

I added cypress-failed-log to my project and for some reason i get the following error: TypeError: Converting circular structure to JSON. Here is a reproducible code:

describe('error code for cypress failed log issue', () => {
   it('should produce an TypeError: Converting circular structure to JSON ', () => {
      cy.visit('xxxx.html'); 
      cy.wrap([
         '[data-test-id="login-user-name"]',
         '[data-test-id="login-user-pwd"]',
         '[data-test-id="login-button"]'
      ]).each( selector => {
         cy.get(selector, { timeout: 30000 } ).should('be.visible');
      });
      /* [
         '[data-test-id="login-user-name"]',
         '[data-test-id="login-user-pwd"]',
         '[data-test-id="login-button"]'
      ].forEach(selector => {
         cy.get(selector, { timeout: 30000 } ).should('be.visible');
      }); */
   });
});

Obviously you have to replace the url xxxx.html that should point to a webpage having elements with the data-test-id attribute set as those in the array. Here is a screenshot of the test runner after I ran the test code up there:

cypress-failed-log-error

Possible to turn off terminal logging but still get JSON file?

I have what is probably a silly question about cypress-failed-log, which I have installed and really like to use for troubleshooting. Is there any way to set it up so that it only does the JSON output but doesn’t include the commands in the terminal? Thanks!

Unable to get this to work

Hi,

I'm using Windows 7 and Cypres 1.1.3, and this is not working. Seemingly nothing is happening. I added package.json script, installed the dependencies, included it in the index.js file in cypress/support. but there's no telling that this ran or did not. it doesnt work.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/badges.yml
.github/workflows/ci.yml
  • cypress-io/github-action v4
  • cycjimmy/semantic-release-action v2
npm
package.json
  • debug 4.3.4
  • logdown 3.3.1
  • cypress 11.2.0
  • semantic-release 19.0.5

  • Check this box to trigger a request for Renovate to run again on this repository

Cypress runner hangs indefinitely when calling "this.skip()" in a test

I have this plugin enabled with my Cypress 11.2.0 suite. We also use Cucumber for our tests so we have the cypress-cucumber-preprocessor plugin enabled as well. Due to some current constraints in our project, we cannot use test isolation and thus need to "fail fast" when a scenario fails in a feature file. Thus, we try to accomplish this with the following Cucumber hook:

const {Before} = require("@badeball/cypress-cucumber-preprocessor");

Before(function () {
    const suite = cy.state('test').parent;
    if (suite.tests.some(test => test.state === 'failed')) {
        cy.log('Failing fast, so all scenarios will be skipped');
        this.skip();
    }
})

I've noticed that calling this.skip() anywhere in the tests, like above, will cause the Cypress runner to hang indefinitely. It will first skip the next scenario, and then be unable to execute any more commands. The runner will need to be manually shut down. I've discovered that by removing the cypress-failed-log plugin, tests can be skipped without any issue, but this plugin basically breaks Cypress when trying to skip a test.

No 'Test failed, details in $1' message in console log

When I run my tests in headless mode, I do not receive any output in my console log, though report is generated.

I have a sample spec with 1 failing test. I launch it using the following command: as-a staging cypress run, where 'staging' is a user in staging env, or CYPRESS_BASE_URL=... cypress run.
In both cases I can see no message 'Test failed, details in $1' in my output. Instead, a file 'failed-exec.json' is generated in the project root folder. It contains the following data:

  "stdout": "",
  "stderr": "/bin/bash: ./on-failed.sh: No such file or directory",
  "code": 127
}

A report file, 'failed-${testname}.json' appears next to it.

I have require('cypress-failed-log'); in my support/index.js and NPM script failed-test in package.json. The cypress-failed-log package is listed under devDependencies in package.json.
Cypress version: 2.1.0
cypress-failed-log: 2.0.0
My tests are running under macOS.

Log during test instead of after?

One of our tests is hanging on the build server and never completes. It would be nice if we could enable this logging so it happens while the test is running, instead of afterwards.

(Yes, I realize this means the logs would occur for successful tests too. That's fine.)

Dependency deprecation warning: nsp (npm)

On registry https://registry.npmjs.org, the "latest" version (v3.2.1) of dependency nsp has the following deprecation notice:

The Node Security Platform service is shutting down 9/30 - https://blog.npmjs.org/post/175511531085/the-node-security-platform-service-is-shutting

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Affected package file(s): package.json

If you don't care about this, you can close this issue and not be warned about nsp's deprecation again. If you would like to completely disable all future deprecation warnings then add the following to your config:

"suppressNotifications": ["deprecationWarningIssues"]

Rerun of failing tests throws generic error instead of correct output.

Prerequisities

[email protected]
[email protected]
@cypress/[email protected]
[email protected]

Example solution here:

https://github.com/keeema/cypress-ts-template/tree/cypress-failed-log_issue_example

Issue

Plugin is not able to re-run failing tests in cypress project with typescript compilation by webpack preprocessor. It just shows generic error.

Scenario:

Run tests in example solution by npx cypress open an Run All Tests.
Let the test run finish.
Re-Run test again in the same window by "Run All Tests" button.

Actual result

First run has correct output:

Timed out retrying: expected false to be true
cypress/integration/examples/test.spec.ts:10:75

... code here

Second run has just generic error:

The following error originated from your application code, not from Cypress.

  > Cannot set property 'err' of undefined

When Cypress detects uncaught errors originating from your application it will automatically fail the current test.

This behavior is configurable, and you can choose to turn this off by listening to the uncaught:exception event.

Expected result

Same output all the time:

Timed out retrying: expected false to be true
cypress/integration/examples/test.spec.ts:10:75

... code here

Additional info

It was working with [email protected] (you can force the version in package.json and try it).

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The push permission to the Git repository is required.

semantic-release cannot push the version tag to the branch master on remote Git repository with URL https://github.com/bahmutov/cypress-failed-log.git.

Please refer to the authentication configuration documentation to configure the Git credentials on your CI environment and make sure the repositoryUrl is configured with a valid Git URL.


Good luck with your project ✨

Your semantic-release bot 📦🚀

How do you specify the directory the generated files go in?

I'd like to put the outputted json files in a folder adjacent to cypress/screenshots, ex. cypress/failure-logs, so that I can upload them in my CI system on failure, and ignore them easily using git when running locally.

How can I specify a target directory to use instead of the package.json root directory?

Thank you for creating this!

Support uncaught:exception

Sometimes test could fail because the application crashes.
It would be nice to get this exception logged as well.

Details for xhr requests

The logging of the commands upon error in the cypress test works fine (it already saved me a couple of hours analyzing issues from test runs on our CI). However the details for the assertion is not always the only information for being able to track down an issue. In some cases it's required to see which requests have been made before/ afterwards.

In the Cypress UI for each XHR request the URL and the status is displayed - but in the logged files on error only the entry xhr exists without further details. Is there any possibility to access the the URL and the status for the xhr command to get this information into the log as well?

Task 'failed' was not handled in the plugins file

The task 'failed' was not handled in the plugins file. The following tasks are registered: cypress-plugin-snapshot:getFile, cypress-plugin-snapshot:matchImage, cypress-plugin-snapshot:matchText, generateOTP
Fix this in your plugins file here:
/home/travis/build/cypress/plugins/index.js

I get this error after installing version 2.9.5 and adding import "cypress-failed-log" to my index.js
I'm running Cypress 9.7.0

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Preset name not found within published preset config (monorepo:babel6). Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Abort on the first failure

I have just updated to version 2.4.0 from 2.1.0 and when one test fails Cypress doesn`t continue the execution. Whereas in the past it would continue executing tests that came next. Is that an expected behavior?

Here is the error message I am getting:
image

Error on trying to install

Hi. It's anyone know whats happening?

In the past works, now cannot install.

Thanks.

npm install --save-dev cypress cypress-failed-log

npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.

[email protected] postinstall /app/node_modules/cypress
node index.js --exec install

internal/modules/cjs/loader.js:905
throw err;
^

Error: Cannot find module 'har-validator'
Require stack:

  • /app/node_modules/@cypress/request/lib/har.js
  • /app/node_modules/@cypress/request/request.js
  • /app/node_modules/@cypress/request/index.js
  • /app/node_modules/cypress/lib/tasks/download.js
  • /app/node_modules/cypress/lib/tasks/install.js
  • /app/node_modules/cypress/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object. (/app/node_modules/@cypress/request/lib/har.js:5:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object. (/app/node_modules/@cypress/request/request.js:23:11)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    '/app/node_modules/@cypress/request/lib/har.js',
    '/app/node_modules/@cypress/request/request.js',
    '/app/node_modules/@cypress/request/index.js',
    '/app/node_modules/cypress/lib/tasks/download.js',
    '/app/node_modules/cypress/lib/tasks/install.js',
    '/app/node_modules/cypress/index.js'
    ]
    }
    npm WARN enoent ENOENT: no such file or directory, open '/app/package.json'
    npm WARN app No description
    npm WARN app No repository field.
    npm WARN app No README data
    npm WARN app No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: node index.js --exec install
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-11-25T12_37_35_241Z-debug.log

I flow this to install:

apt-get update -yq
apt-get install curl gnupg -yq
curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt-get install -y nodejs
apt-get install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
npm install --save-dev cypress cypress-failed-log
npm install cypress-mochawesome-reporter
npx @bahmutov/cly init

afterEach failure: `this` is undefined

Once installing this plugin, my afterEach broke because I'm referencing this.currentTest:

TypeError: Cannot read property 'currentTest' of undefined

In src/index.js why not perform call on fn like with onFailed?

  _afterEach(name, function () {
    onFailed.call(this)
    fn.call(this)
  })

This fixes it for me. Should I submit a PR?

同学,您这个项目引入了698个开源组件,存在20个漏洞,辛苦升级一下

检测到 bahmutov/cypress-failed-log 一共引入了698个开源组件,存在20个漏洞

漏洞标题:Eran Hammer cryptiles 安全漏洞
缺陷组件:[email protected]
漏洞编号:CVE-2018-1000620
漏洞描述:Eran Hammer cryptiles是一款通用加密工具。
Eran Hammer cryptiles 4.1.1之前版本中的randomDigits()方法存在安全漏洞。攻击者可利用该漏洞暴力破解随机数。
影响范围:[3.1.0, 3.1.3)
最小修复版本:3.1.3
缺陷组件引入路径:[email protected]>[email protected]>[email protected]>[email protected]>[email protected]

另外还有20个漏洞,详细报告:https://mofeisec.com/jr?p=afba38

The 'task' event has not been registered in the plugins file

I have been using this plugin successfully for a while.

// cypress/plugins/index.js
modules.exports = (on, config) => {
  on('task', {
    failed: require('cypres-failed-log/src/failed')()
  });
};
// cypress/support/index.js
import 'cypress-failed-log';

However, recently I switched to esmodule by adding this in package.json

  "type": "module"

I renamed cypress/plugins/index.js to cypress/plugins/index.cjs. Cypress run fails, but upon failure, I got the following error message

      CypressError: `cy.task('failed')` failed with the following error:

The 'task' event has not been registered in the plugins file. You must register it before using cy.task()

Is there anything special I need to do fix this?

Throwing error every time the test if failed - "path.basename is not a function"

@bahmutov
When running our e2e test with the cypress-failed-log plugin, whenever the test is failed for any reason, "path.basename is not a function" is displayed in the cypress runner.

Using below versions:
"cypress-failed-log": "^2.9.1",
"cypress": "^8.3.1",
"@neuralegion/cypress-har-generator": "^5.2.3"

One possible theory is that this error started to pop up after installing a cypress-har-generator plugin. Maybe a module collision or something?

Refer attached screenshot for reference error.

Any help or workaround for this issue will be really appreciated.

Screenshot 2021-10-01 at 11 11 59 AM

Writing JSON log file fails if test name is too long

Especially if you have an it block nested within several describe blocks, the file name used for the JSON file can get very long. If the name cypress-failed-log tries to use for the file name gets too long, Cypress fails with a message to the effect that cy.writefile() failed due to the file name being too long.

It would be nice to be able to configure the pattern used for the file name, but it should at least not fail to write the file, which also prevents the rest of the tests from running since it appears cypress-failed-log performs this in an "after each" hook.

does not work in Cypress v6

Seems it saves file with a different name from expected (during testing)

  • saves cypress/logs/failed-a-r-5-root-suite-first-context-has-second-test-failing.json
  • finds cypress/logs/failed-a-root-suite-first-context-has-second-test-failing.json

Add support for retries specified in each individual test (as opposed to global config)

Hi @bahmutov,

I was wondering if this is something that could be useful ? If so I can open a PR.
I noticed the plugin reads the retries configuration when it is first imported (in this line)

Let's say that I have the retries set to 2 in the global cypress.config.js but I want to change that for a specific test.
So I do this :

it('dummy', { retries: 3 }, () => {
  // ... some commands ...
})

I think the retries setting of 3 will not be honoured given the place where the plugin reads it, am I correct ?
If so, I was wondering if this could help instead :

// inside of onFailed function

if (this.currentTest.final) {
    const filepath = writeFailedTestInfo(info)
    debug('saving the log file %s', filepath)
    info.filepath = filepath
  }

If the final property is not available in older versions of cypress (not sure), then maybe the plugin could fallback to reading the Cypress.config('retries') ad-hoc, inside the onFailed function as opposed to once at the beginning ?

Let me know if this is something you would be open to ?

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.