Skip to content

Commit

Permalink
feat: remove screenshotting (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
c32hedge authored May 4, 2020
1 parent 7f035f9 commit be87845
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 55 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ suiteName - the parent suite name
testName - full name of the test, including the suite name
testError - error message string
testCommands - array of strings, last failing command is last
screenshot - filename of PNG file taken right after failure
```

## Example
Expand All @@ -75,8 +74,7 @@ and each test command before the test are recorded
"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"
],
"screenshot": "loads-the-about-tab.png"
]
}
```

Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/test-page1-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('cypress failed log', () => {

afterEach(function makeDummyCommands () {
// more dummy commands on purpose. Can we get
// the right screenshot when the test actual failed?
// the right command list when the actual test failed?
cy
.wait(100)
.wait(100)
Expand Down
19 changes: 0 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@
"version": "0.0.0-development",
"author": "Gleb Bahmutov <[email protected]>",
"bugs": "https://github.com/bahmutov/cypress-failed-log/issues",
"config": {
"pre-git": {
"pre-commit": [
"npm prune",
"npm run deps",
"npm test",
"npm run ban"
],
"pre-push": [
"npm run stop-only",
"npm run license",
"npm run ban -- --all",
"npm run size"
],
"post-commit": [],
"post-merge": []
}
},
"engines": {
"node": ">=6"
},
Expand Down Expand Up @@ -78,7 +60,6 @@
"lodash": "4.17.15",
"mocha": "7.1.2",
"mocha-banner": "1.1.2",
"pre-git": "3.17.1",
"prettier-standard": "16.3.0",
"rimraf": "3.0.2",
"semantic-release": "17.0.7",
Expand Down
28 changes: 7 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function writeFailedTestInfo ({
testId,
testName,
testError,
testCommands,
screenshot
testCommands
}) {
const info = {
specName,
Expand All @@ -30,8 +29,7 @@ function writeFailedTestInfo ({
testId,
testName,
testError,
testCommands,
screenshot
testCommands
}
const str = JSON.stringify(info, null, 2) + '\n'
const cleaned = getCleanFilename(
Expand Down Expand Up @@ -101,11 +99,6 @@ function onFailed () {
doneWithTest(testName)

const title = this.currentTest.title
const screenshotName = `${getCleanFilename(title)} (failed)`

cy.wait(1000).log('waited for UI before capturing screenshot')
cy.screenshot(screenshotName)
cy.wait(1000)

const suiteName = this.currentTest.parent && this.currentTest.parent.title

Expand All @@ -121,8 +114,6 @@ function onFailed () {

const specName = path.basename(window.location.pathname)

const screenshot = `${screenshotName}.png`

console.log('=== test failed ===')
console.log(specName)
console.log('=== title ===')
Expand All @@ -135,8 +126,6 @@ function onFailed () {
console.log(testError)
console.log('=== commands ===')
console.log(testCommands.join('\n'))
console.log('=== screenshot ===')
console.log(screenshot)

const info = {
specName,
Expand All @@ -145,19 +134,17 @@ function onFailed () {
testId,
testName,
testError,
testCommands,
screenshot
testCommands
}
writeFailedTestInfo(info)

cy.task('failed', info, { log: false })
}

// We have to do a hack to make sure OUR "afterEach" callback function
// runs BEFORE any user supplied "afterEach" callback. This is necessary
// to take screenshot of the failure AS SOON AS POSSIBLE.
// Otherwise commands executed by the user callback might destroys the
// screen and add too many commands to the log, making post-mortem
// runs BEFORE any user supplied "afterEach" callback.
// Otherwise commands executed by the user callback might
// add too many commands to the log, making post-mortem
// triage very difficult. In this case we just wrap client supplied
// "afterEach" function with our callback "onFailed". This ensures we run
// first.
Expand All @@ -179,8 +166,7 @@ afterEach = (name, fn) => {
fn = name
name = fn.name
}
// before running the client function "fn"
// run our "onFailed" to capture the screenshot sooner
// run our "onFailed" before running the client function "fn"
_afterEach(name, function () {
// run callbacks with context "this"
onFailed.call(this)
Expand Down
11 changes: 0 additions & 11 deletions test/verify-failed-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ const jsonFiles = [
'failed-cypress-failed-log-finds-aliens.json'
]

const cypress = require(inParentFolder('cypress.json'))
const screenshotsFolder = inParentFolder(
cypress.screenshotsFolder || 'cypress/screenshots')
console.log('screenshots in folder', screenshotsFolder)

const logsFolder = inParentFolder('cypress/logs')
console.log('logs in folder', logsFolder)

Expand Down Expand Up @@ -44,12 +39,6 @@ function checkJsonFile (filename) {
la(result.testCommands[0].startsWith('visit'),
'expected first command to be visit', result.testCommands)

const screenshot = result.screenshot
la(is.unemptyString(screenshot), 'could not find screenshot', result)
const screenshotFilename = path.join(screenshotsFolder, screenshot)
la(fs.existsSync(screenshotFilename),
'could not find screenshot image', screenshotFilename)

console.log('file %s looks ok', jsonFilename)
}

Expand Down

0 comments on commit be87845

Please sign in to comment.