Closed kaiyoma closed 4 years ago
@kaiyoma This is separate from Cypress as a product and is essentially just saving terminal output to a file. This will largely depend on the operating system you use. See https://askubuntu.com/questions/420981/how-do-i-save-terminal-output-to-a-file https://stackoverflow.com/questions/14500616/windows-command-prompt-log-to-a-file
@jennifer-shehane I don't think this is an OS issue. I've already tried writing the debug logs to a file, but when I do this, I lose all the good screen output. I've also tried using tee
and grep
to separate the two, but there's no good way to do that either, as there doesn't seem to be a way to reliably differentiate debug logs from normal logs. Filtering on lines containing cypress:
is a start, but misses a lot of log messages.
I really think this is something that Cypress should try to support. Currently, we're running into lots of reliability issues with Cypress (it dies/stalls for seemingly no reason) and the debug logs could really help us here, if they were being written to a file and not to the screen.
@kaiyoma we use debug module to output debug logs, and they are all written to STDERR stream. You should be able to redirect the STDERR output to a file, while leaving the normal STDOUT output in the terminal. For example on Linux and Mac to redirect the STDERR output you would do 2> filename
DEBUG=cypress:server:* npx cypress run --spec 'cypress/integration/examples/n*' 2> logs.txt
I have opened https://github.com/cypress-io/cypress-documentation/issues/3002 to update our docs with this advice
@bahmutov Ah, this is extremely useful info, thank you! I'll try this out today.
Hmm, turns out this doesn't really work. A few of the debug messages are sent to STDERR, and I can redirect those to a file, but it would seem that most are not. Try running Cypress with DEBUG=cypress:*
and you'll see all the messages that aren't going to STDERR.
I am using Bash on Mac
DEBUG=cypress:* npx cypress run --spec 'cypress/integration/examples/n*' 1> stdout.txt 2> logs.txt
stdout.txt is nice and clean
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 4.10.0 │
│ Browser: Electron 80 (headless) │
│ Specs: 2 found (examples/navigation.spec.js, examples/network_requests.spec.js) │
│ Searched: cypress/integration/examples/n* │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: examples/navigation.spec.js (1 of 2)
Navigation
✓ cy.go() - go back or forward in the browser's history (971ms)
✓ cy.reload() - reload the page (455ms)
✓ cy.visit() - visit a remote url (442ms)
3 passing (3s)
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 3 │
│ Passing: 3 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: 2 seconds │
│ Spec Ran: examples/navigation.spec.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /Users/gleb/git/cypress-example-kitchensink/cypress/videos/ (0 seconds)
examples/navigation.spec.js.mp4
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: examples/network_requests.spec.js (2 of 2)
Network Requests
✓ cy.server() - control behavior of network requests and responses (225ms)
✓ cy.request() - make an XHR request (490ms)
✓ cy.request() - verify response using BDD syntax (394ms)
✓ cy.request() with query parameters (391ms)
✓ cy.request() - pass result to the second request (374ms)
✓ cy.request() - save response in the shared test context (348ms)
✓ cy.route() - route responses to matching requests (1067ms)
7 passing (4s)
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 7 │
│ Passing: 7 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: 4 seconds │
│ Spec Ran: examples/network_requests.spec.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
(Video)
- Started processing: Compressing to 32 CRF
- Finished processing: /Users/gleb/git/cypress-example-kitchensink/cypress/videos/ (0 seconds)
examples/network_requests.spec.js.mp4
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ examples/navigation.spec.js 00:02 3 3 - - - │
├────────────────────────────────────────────────────────────────────────────────────────────────┤
│ ✔ examples/network_requests.spec.js 00:04 7 7 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! 00:07 10 10 - - -
logs.txt has everything else, I cannot even paste it, it is too large. Here is the start
2020-07-17T17:14:02.786Z cypress:cli:cli cli starts with arguments ["/Users/gleb/.nvm/versions/node/v12.16.1/bin/node","/Users/gleb/git/cypress-example-kitchensink/node_modules/.bin/cypress","run","--spec","cypress/integration/examples/n*"]
2020-07-17T17:14:02.787Z cypress:cli NODE_OPTIONS is not set
2020-07-17T17:14:02.787Z cypress:cli:cli program parsing arguments
2020-07-17T17:14:02.790Z cypress:cli:cli running Cypress with args [ Command { commands: [], options: [ [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option] ], _execs: Set {}, _allowUnknownOption: false, _args: [], _name: 'run', _optionValues: {}, _storeOptionsAsProperties: true, _passCommandToAction: true, _actionResults: [], _helpFlags: '-h, --help', _helpDescription: 'output usage information', _helpShortFlag: '-h', _helpLongFlag: '--help', _noHelp: false, _exitCallback: undefined, _executableFile: undefined, parent: Command { commands: [Array], options: [Array], _execs: Set {}, _allowUnknownOption: false, _args: [], _name: 'cypress', _optionValues: {}, _storeOptionsAsProperties: true, _passCommandToAction: true, _actionResults: [], _helpFlags: '-h, --help', _helpDescription: 'output usage information', _helpShortFlag: '-h', _helpLongFlag: '--help', _usage: '<command> [options]', _events: [Object: null prototype], _eventsCount: 9, rawArgs: [Array], args: [] }, _usage: '[options]', _description: 'Runs Cypress tests from the CLI without the GUI', _argsDescription: undefined, _events: [Object: null prototype] { 'option:browser': [Function], 'option:ci-build-id': [Function], 'option:config': [Function], 'option:config-file': [Function], 'option:env': [Function], 'option:group': [Function], 'option:key': [Function], 'option:headed': [Function], 'option:headless': [Function], 'option:no-exit': [Function], 'option:parallel': [Function], 'option:port': [Function], 'option:project': [Function], 'option:quiet': [Function], 'option:record': [Function], 'option:reporter': [Function], 'option:reporter-options': [Function], 'option:spec': [Function], 'option:tag': [Function], 'option:dev': [Function] }, _eventsCount: 20, exit: true, spec: 'cypress/integration/examples/n*' } ]
2020-07-17T17:14:02.932Z cypress:cli:cli variable-length opts parsed { args: [ '/Users/gleb/.nvm/versions/node/v12.16.1/bin/node', '/Users/gleb/git/cypress-example-kitchensink/node_modules/.bin/cypress', 'run', '--spec', 'cypress/integration/examples/n*' ], opts: Command { commands: [], options: [ [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option], [Option] ], _execs: Set {}, _allowUnknownOption: false, _args: [], _name: 'run', _optionValues: {}, _storeOptionsAsProperties: true, _passCommandToAction: true, _actionResults: [], _helpFlags: '-h, --help', _helpDescription: 'output usage information', _helpShortFlag: '-h', _helpLongFlag: '--help', _noHelp: false, _exitCallback: undefined, _executableFile: undefined, parent: Command { commands: [Array], options: [Array], _execs: Set {}, _allowUnknownOption: false, _args: [], _name: 'cypress', _optionValues: {}, _storeOptionsAsProperties: true, _passCommandToAction: true, _actionResults: [], _helpFlags: '-h, --help', _helpDescription: 'output usage information', _helpShortFlag: '-h', _helpLongFlag: '--help', _usage: '<command> [options]', _events: [Object: null prototype], _eventsCount: 9, rawArgs: [Array], args: [] }, _usage: '[options]', _description: 'Runs Cypress tests from the CLI without the GUI', _argsDescription: undefined, _events: [Object: null prototype] { 'option:browser': [Function], 'option:ci-build-id': [Function], 'option:config': [Function], 'option:config-file': [Function], 'option:env': [Function], 'option:group': [Function], 'option:key': [Function], :
...
Weird, I can't repro this behavior, at least not on Windows 10. Guess I'll keep hacking on this and try pushing a change to our Linux build servers. (Maybe it's somehow a Windows 10 git bash issue?)
Might be. This is why providing OS information is helpful when opening a GitHub issue, imho
On Fri, Jul 17, 2020 at 1:43 PM Kyle Getz notifications@github.com wrote:
Weird, I can't repro this behavior, at least not on Windows 10. Guess I'll keep hacking on this and try pushing a change to our Linux build servers. (Maybe it's somehow a Windows 10 git bash issue?)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cypress-io/cypress/issues/7995#issuecomment-660249931, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ4BJUI5EZ3DNWHIBQMQD3R4CEVVANCNFSM4O3C7YAQ .
-- Dr. Gleb Bahmutov, PhD
Schedule video chat / phone call / meeting with me via https://calendly.com/bahmutov gleb.bahmutov@gmail.com @bahmutov https://twitter.com/@bahmutov https://glebbahmutov.com/ https://glebbahmutov.com/blog https://github.com/bahmutov
Looks like the STDERR redirect is working correctly in Linux, which is all I need to further troubleshoot the other Cypress issues. Thanks for the suggestion!
In my testing of
DEBUG=cypress:* npx cypress run 1> stdout.txt 2> logs.txt
I also found that it didn't work properly on Windows. It put most of it into stdout and hardly any into stderr. On Linux though it woks as expected. Probably more likely an issue with the debug package though, not cypress, I would assume.
@kaiyoma we use debug module to output debug logs, and they are all written to STDERR stream. You should be able to redirect the STDERR output to a file, while leaving the normal STDOUT output in the terminal. For example on Linux and Mac to redirect the STDERR output you would do
2> filename
DEBUG=cypress:server:* npx cypress run --spec 'cypress/integration/examples/n*' 2> logs.txt
I have opened cypress-io/cypress-documentation#3002 to update our docs with this advice
@kaiyoma we use debug module to output debug logs, and they are all written to STDERR stream. You should be able to redirect the STDERR output to a file, while leaving the normal STDOUT output in the terminal. For example on Linux and Mac to redirect the STDERR output you would do
2> filename
DEBUG=cypress:server:* npx cypress run --spec 'cypress/integration/examples/n*' 2> logs.txt
I have opened cypress-io/cypress-documentation#3002 to update our docs with this advice
Is there a way to accomplish this in the cypress config?
Current behavior:
If you enable debug logging as per the Cypress instructions, everything gets logged to the screen, but this is highly undesirable IMO. It drowns out the normal output and overwhelms the UI used to view CI logs. Put simply, it's just too much data to be printing to the screen.
Desired behavior:
A mechanism by which debug logs are enabled, but they are written to a file only. Screen output would stay the same. This is the best of both worlds: the normal Cypress output is preserved, but advanced debugging logs are still available if needed. Many other tools / apps operate in this manner.
Test code to reproduce
Run any test with debug logging turned on.