Skip to content

Commit

Permalink
feat: Add configuration option for disabling screenshots (#8083)
Browse files Browse the repository at this point in the history
Co-authored-by: Jennifer Shehane <[email protected]>
  • Loading branch information
laistomazz and jennifer-shehane authored Jul 28, 2020
1 parent dbe88da commit fbce860
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
"default": "cypress/plugins/index.js",
"description": "Path to plugins file. (Pass false to disable)"
},
"screenshotOnRunFailure": {
"type": "boolean",
"default": true,
"description": "Whether Cypress will take a screenshot when a test fails during cypress run"
},
"screenshotsFolder": {
"type": "string",
"default": "cypress/screenshots",
Expand Down
5 changes: 5 additions & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,11 @@ declare namespace Cypress {
* @example 1.2.3
*/
resolvedNodeVersion: string
/**
* Whether Cypress will take a screenshot when a test fails during cypress run.
* @default true
*/
screenshotOnRunFailure: boolean
/**
* Path to folder where screenshots will be saved from [cy.screenshot()](https://on.cypress.io/screenshot) command or after a headless or CI run’s test failure
* @default "cypress/screenshots"
Expand Down
19 changes: 19 additions & 0 deletions packages/driver/cypress/integration/commands/screenshot_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ describe('src/cy/commands/screenshot', () => {
})
})

it('is noop when screenshotOnRunFailure is false', () => {
Cypress.config('isInteractive', false)
Cypress.config('screenshotOnRunFailure', false)

cy.spy(Cypress, 'action').log(false)

const test = {
err: new Error,
}

const runnable = cy.state('runnable')

Cypress.action('runner:runnable:after:run:async', test, runnable)
.then(() => {
expect(Cypress.action).not.to.be.calledWith('cy:test:set:state')
expect(Cypress.automation).not.to.be.called
})
})

it('sends before/after events', function () {
Cypress.config('isInteractive', false)
this.screenshotConfig.scale = false
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ module.exports = function (Commands, Cypress, cy, state, config) {
Cypress.on('runnable:after:run:async', (test, runnable) => {
const screenshotConfig = $Screenshot.getConfig()

if (!test.err || !screenshotConfig.screenshotOnRunFailure || config('isInteractive') || test.err.isPending) {
if (!test.err || !screenshotConfig.screenshotOnRunFailure || config('isInteractive') || test.err.isPending || !config('screenshotOnRunFailure')) {
return
}

Expand Down
3 changes: 3 additions & 0 deletions packages/server/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ viewportHeight responseTimeout
video taskTimeout
videoCompression
videoUploadOnPasses
screenshotOnRunFailure
watchForFileChanges
waitForAnimations resolvedNodeVersion
nodeVersion resolvedNodePath
Expand Down Expand Up @@ -142,6 +143,7 @@ const CONFIG_DEFAULTS = {
video: true,
videoCompression: 32,
videoUploadOnPasses: true,
screenshotOnRunFailure: true,
modifyObstructiveCode: true,
chromeWebSecurity: true,
waitForAnimations: true,
Expand Down Expand Up @@ -212,6 +214,7 @@ const validationRules = {
videoCompression: v.isNumberOrFalse,
videosFolder: v.isString,
videoUploadOnPasses: v.isBoolean,
screenshotOnRunFailure: v.isBoolean,
viewportHeight: v.isNumber,
viewportWidth: v.isNumber,
waitForAnimations: v.isBoolean,
Expand Down
16 changes: 16 additions & 0 deletions packages/server/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,20 @@ describe('lib/config', () => {
})
})

context('screenshotOnRunFailure', () => {
it('passes if a boolean', function () {
this.setup({ screenshotOnRunFailure: false })

return this.expectValidationPasses()
})

it('fails if not a boolean', function () {
this.setup({ screenshotOnRunFailure: 42 })

return this.expectValidationFails('be a boolean')
})
})

context('viewportHeight', () => {
it('passes if a number', function () {
this.setup({ viewportHeight: 10 })
Expand Down Expand Up @@ -1125,6 +1139,7 @@ describe('lib/config', () => {
video: { value: true, from: 'default' },
videoCompression: { value: 32, from: 'default' },
videoUploadOnPasses: { value: true, from: 'default' },
screenshotOnRunFailure: { value: true, from: 'default' },
videosFolder: { value: 'cypress/videos', from: 'default' },
supportFile: { value: 'cypress/support', from: 'default' },
pluginsFile: { value: 'cypress/plugins', from: 'default' },
Expand Down Expand Up @@ -1201,6 +1216,7 @@ describe('lib/config', () => {
video: { value: true, from: 'default' },
videoCompression: { value: 32, from: 'default' },
videoUploadOnPasses: { value: true, from: 'default' },
screenshotOnRunFailure: { value: true, from: 'default' },
videosFolder: { value: 'cypress/videos', from: 'default' },
supportFile: { value: 'cypress/support', from: 'default' },
pluginsFile: { value: 'cypress/plugins', from: 'default' },
Expand Down

4 comments on commit fbce860

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fbce860 Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/linux-x64/circle-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-407878/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/circle-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-407855/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fbce860 Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-x64/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fbce860 Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/win32-ia32/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.0.0/appveyor-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-34336945/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on fbce860 Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.0.0/darwin-x64/circle-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-407886/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.0.0/circle-develop-fbce860f310e71b16a86e8a676f51696f2d45c9e-407880/cypress.tgz

Please sign in to comment.