Skip to content

No screenshots when DEBUG logs are activated #6662

Closed
@Konstruktour

Description

@Konstruktour

Current behavior:

The testscript (test.spec.js)

describe('Screenshot-Test', () => {
    it('should create screenshots', () => {
        cy.visit('http://localhost:8080/index.html');
        cy.screenshot('a');
    });
});

is executed via the module api

var cypress = require('cypress/index');
process.env.DEBUG = 'cypress:*';
cypress.run({
    spec: 'cypress/integration/test.spec.js',
});

When the debug logs are activated, no screenshots are created, followed by the error message

Error: unexpected end of file
at Zlib.zlibOnError [as onerror] (zlib.js:170:17)
at Inflate._processChunk ....

Without the debug logs, creating screenshots work as expected.

Desired behavior:

Screenshots should also be created when debug logs are activated.

Versions

Cypress 4.0.2 / 4.1.0
Windows 10 / Linux
No cypress configs

Activity

jennifer-shehane

jennifer-shehane commented on Mar 9, 2020

@jennifer-shehane
Member

@Konstruktour Thank you for providing a reproducible example!

I am able to recreate this.

  • This only happens starting in Cypress 3.8.0.
  • This only happens within the Electron browser (does not happen if you pass browser: 'chrome' to cypress.run)

This helped me narrow does the logging necessary to recreate to the specific logs from cypress:server:browsers:electron.

This may be due to something in this diff of the electron.coffee file between 3.7.0 and 3.8.0. Seems to be the changes are from this PR: #5849 cc @flotwig

v3.7.0...v3.8.0#diff-ab788b716b2ba4290d63618c58f3cbe4

script.js

const cypress = require('cypress')
process.env.DEBUG = 'cypress:server:browsers:electron';

cypress.run({
  spec: 'cypress/integration/spec.js'
})

spec.js

it('should create screenshots', () => {
  cy.screenshot()
})

Logs of running node script.js ends up throwing err

 node script.js

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    4.1.0                                                                              │
  │ Browser:    Electron 78 (headless)                                                             │
  │ Specs:      1 found (spec.js)                                                                  │
  │ Searched:   cypress/integration/spec.js                                                        │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  spec.js                                                                         (1 of 1)
  cypress:server:browsers:electron open { browser: { name: 'electron', channel: 'stable', family: 'chromium', displayName: 'Electron', version: '78.0.3904.130', path: '', majorVersion: 78, info: 'Electron is the default browser that comes with Cypress. This is the default browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.', isHeadless: true, isHeaded: false }, url: 'http://localhost:54740/__/#/tests/integration/spec.js' } +0ms
  cypress:server:browsers:electron received saved state {} +2ms
  cypress:server:browsers:electron browser window options { width: 1280, height: 720, show: false, recordFrameRate: 20, automationMiddleware: { onAfterResponse: [Function: onAfterResponse] }, projectRoot: '/Users/jennifer/Dev/cypress-transform-test', browsers: [ { name: 'chrome', family: 'chromium', channel: 'stable', displayName: 'Chrome', version: '80.0.3987.132', path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', majorVersion: 80 }, { name: 'chromium', family: 'chromium', channel: 'stable', displayName: 'Chromium', version: '78.0.3904.0', path: '/Applications/Chromium.app/Contents/MacOS/Chromium', majorVersion: 78 }, { name: 'chrome', family: 'chromium', channel: 'canary', displayName: 'Canary', version: '82.0.4078.2', path: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary', majorVersion: 82 }, { name: 'firefox', family: 'firefox', channel: 'stable', displayName: 'Firefox', version: '72.0.2', path: '/Applications/Firefox.app/Contents/MacOS/firefox-bin', info: 'Firefox support is currently in beta! You can help us continue to improve the Cypress + Firefox experience by [reporting any issues you find](https://on.cypress.io/new-issue).', majorVersion: 72, warning: 'Your project has set the configuration option: `chromeWebSecurity: false`\n' + '\n' + 'This option will not have an effect in Firefox. Tests that rely on web security being disabled will not run as expected.' }, { name: 'firefox', family: 'firefox', channel: 'dev', displayName: 'Firefox Developer Edition', version: '73.0', path: '/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox-bin', info: 'Firefox support is currently in beta! You can help us continue to improve the Cypress + Firefox experience by [reporting any issues you find](https://on.cypress.io/new-issue).', majorVersion: 73, warning: 'Your project has set the configuration option: `chromeWebSecurity: false`\n' + '\n' + 'This option will not have an effect in Firefox. Tests that rely on web security being disabled will not run as expected.' }, { name: 'edge', family: 'chromium', channel: 'stable', displayName: 'Edge', version: '80.0.361.66', path: '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge', majorVersion: 80 }, { name: 'edge', family: 'chromium', channel: 'canary', displayName: 'Edge Canary', version: '82.0.446.0', path: '/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary', majorVersion: 82 }, { name: 'edge', family: 'chromium', channel: 'beta', displayName: 'Edge Beta', version: '81.0.416.20', path: '/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta', majorVersion: 81 }, { name: 'edge', family: 'chromium', channel: 'dev', displayName: 'Edge Dev', version: '82.0.439.1', path: '/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev', majorVersion: 82 }, { name: 'electron', channel: 'stable', family: 'chromium', displayName: 'Electron', version: '78.0.3904.130', path: '', majorVersion: 78, info: 'Electron is the default browser that comes with Cypress. This is the default browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.' } ], proxyUrl: 'http://localhost:54740', userAgent: null, proxyServer: 'http://localhost:54740', socketIoRoute: '/__socket.io', chromeWebSecurity: false, url: 'http://localhost:54740/__/#/tests/integration/spec.js', isTextTerminal: true, browser: { name: 'electron', channel: 'stable', family: 'chromium', displayName: 'Electron', version: '78.0.3904.130', path: '', majorVersion: 78, info: 'Electron is the default browser that comes with Cypress. This is the default browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.', isHeadless: true, isHeaded: false }, x: null, y: null, devTools: false, minWidth: 100, minHeight: 100, contextMenu: true, partition: 'persist:run-58397', trackState: { width: 'browserWidth', height: 'browserHeight', x: 'browserX', y: 'browserY', devTools: 'isBrowserDevToolsOpen' }, frame: true, webPreferences: { partition: null, webSecurity: true, nodeIntegration: false, backgroundThrottling: false } } +1ms
  cypress:server:browsers:electron launching browser window to url: http://localhost:54740/__/#/tests/integration/spec.js +2ms
  cypress:server:browsers:electron debugger attached +40ms
  cypress:server:browsers:electron debugger: sending Browser.getVersion with params undefined +0ms
  cypress:server:browsers:electron debugger: received response to Browser.getVersion: { jsVersion: '7.8.279.23', product: 'Chrome/78.0.3904.130', protocolVersion: '1.3', revision: '@8465e366cd1a2a8d2e76331805514b517697ec88', userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/4.1.0 Chrome/78.0.3904.130 Electron/7.1.13 Safari/537.36' } +0ms
  cypress:server:browsers:electron clearing cache +12ms
  cypress:server:browsers:electron debugger: enable Console and Network +621ms
  cypress:server:browsers:electron debugger: sending Console.enable with params undefined +0ms
  cypress:server:browsers:electron debugger: sending Network.enable with params undefined +0ms
  cypress:server:browsers:electron debugger: received response to Console.enable: {} +12ms
  cypress:server:browsers:electron debugger: received response to Network.enable: {} +0ms
  cypress:server:browsers:electron console message: { column: 32, level: 'log', line: 168422, source: 'console-api', text: 'console.clear', url: 'http://localhost:54740/__cypress/runner/cypress_runner.js' } +94ms
  cypress:server:browsers:electron console message: { column: 32, level: 'log', line: 168422, source: 'console-api', text: 'console.clear', url: 'http://localhost:54740/__cypress/runner/cypress_runner.js' } +68ms


  cypress:server:browsers:electron debugger: sending Network.getAllCookies with params undefined +833ms
  cypress:server:browsers:electron debugger: received response to Network.getAllCookies: { cookies: [] } +0ms
  cypress:server:browsers:electron debugger: sending Page.captureScreenshot with params undefined +14ms
  cypress:server:browsers:electron debugger: received response to Page.captureScreenshot: { data: 'iVBORw0KGgoAAAANSUhEUgAABQAAAALQCAYAAADPfd1WAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3WlYVdXix/EfHkAZVISQQREB [truncated]' } +328ms
  cypress:server:browsers:electron debugger: sending Page.captureScreenshot with params undefined +21ms
  cypress:server:browsers:electron debugger: received response to Page.captureScreenshot: { data: 'iVBORw0KGgoAAAANSUhEUgAABQAAAALQCAYAAADPfd1WAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3Xl8VPW9P/7XOWf2THayL0AS [truncated]' } +304ms
  1) should create screenshots

  0 passing (694ms)
  1 failing

  1)  should create screenshots:
     Error: unexpected end of file
      at Zlib.zlibOnError [as onerror] (zlib.js:170:17)
      at Inflate._processChunk (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/pngjs/lib/sync-inflate.js:110:28)
      at zlibBufferSync (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/pngjs/lib/sync-inflate.js:151:17)
      at inflateSync (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/pngjs/lib/sync-inflate.js:155:10)
      at module.exports (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/pngjs/lib/parser-sync.js:85:20)
      at Object.exports.read [as image/png] (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/pngjs/lib/png-sync.js:10:10)
      at Jimp.parseBitmap (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@jimp/core/dist/utils/image-bitmap.js:115:53)
      at Jimp.parseBitmap (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@jimp/core/dist/index.js:521:32)
      at new Jimp (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@jimp/core/dist/index.js:474:13)
      at _construct (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@babel/runtime/helpers/construct.js:30:21)
      at /Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@jimp/core/dist/index.js:1016:32
      at new Promise (<anonymous>:null:null)
      at Function.Jimp.read (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@jimp/core/dist/index.js:1015:10)
      at /Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/lib/screenshots.js:102:21
      at tryCatcher (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues (/Users/jennifer/Library/Caches/Cypress/4.1.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:439:21)





  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      0                                                                                │
  │ Failing:      1                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        true                                                                             │
  │ Duration:     0 seconds                                                                        │
  │ Spec Ran:     spec.js                                                                          │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

  cypress:server:browsers:electron closed event fired +1s
  cypress:server:browsers:electron debugger detached due to { reason: 'target closed' } +4ms

  (Video)

  -  Started processing:  Compressing to 32 CRF
  -  Finished processing: /Users/jennifer/Dev/cypress-transform-test/cypress/videos/s    (0 seconds)
                          pec.js.mp4


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✖  spec.js                                  689ms        1        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✖  1 of 1 failed (100%)                     689ms        1        -        1        -        -

flotwig

flotwig commented on Mar 9, 2020

@flotwig
Contributor

Starting to see this in the PR to upgrade to Electron 8 as well: #6555 According to the debug logs, for some reason, Page.captureScreenshot doesn't receive a response until the test times out and a second Page.captureScreenshot is taken (due to the failure), which seems to immediately return.

Failure is only in 7_record_spec: https://circleci.com/gh/cypress-io/cypress/275151?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

flotwig

flotwig commented on Mar 9, 2020

@flotwig
Contributor

I see the issue. When cypress:server:browsers:electron's debug flag is enabled, the res object is cloned so that res.data (the screenshot PNG) can be truncated for readability:

.then((res) => {
if (debug.enabled && (_.get(res, 'data.length') > 100)) {
res = _.clone(res)
res.data = `${res.data.slice(0, 100)} [truncated]`
}
debug('debugger: received response to %s: %o', message, res)
return res
}).catch((err) => {

However, the cloned res object ends up getting returned 🤦‍♂️ I'll open a PR to fix this.

self-assigned this
on Mar 9, 2020

6 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

browser: electronpkg/serverThis is due to an issue in the packages/server directorytype: regressionA bug that didn't appear until a specific Cy version releasev3.8.0 🐛Issue present since 3.8.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @flotwig@jennifer-shehane@Konstruktour

    Issue actions

      No screenshots when DEBUG logs are activated · Issue #6662 · cypress-io/cypress