Last active
October 24, 2019 02:16
-
-
Save ajs139/3ddc10e807ee9b94b581c80a762de587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('expect-puppeteer'); | |
const isCI = require('is-ci'); | |
const path = require('path'); | |
const { mkdirp, writeFile } = require('fs-extra'); | |
const screenshotsPath = path.resolve(__dirname, '../reports/screenshots'); | |
const toFilename = s => s.replace(/[^a-z0-9.-]+/gi, '_'); | |
const saveScreenshot = async (screenshot, testName) => { | |
await mkdirp(screenshotsPath); | |
const fileName = toFilename(`${new Date().toISOString()}_${testName}_screenshot.png`); | |
const filePath = path.join(screenshotsPath, fileName); | |
await writeFile(filePath, screenshot); | |
return filePath; | |
}; | |
let currentTest = ''; | |
let currentScreenshot = null; | |
if (isCI) { | |
jasmine.getEnv().addReporter({ | |
specStarted: ({ fullName }) => { | |
currentTest = fullName; | |
currentScreenshot = null; | |
}, | |
specDone: async ({ status, fullName }) => { | |
if (status === 'failed') { | |
if(currentScreenshot) { | |
try { | |
const filePath = await saveScreenshot(currentScreenshot, currentTest); | |
console.error(`FAILED ${fullName}: screenshot @ ${filePath}`); | |
} catch (e) { | |
console.error(`FAILED ${fullName}: could not save screenshot.`, e); | |
} | |
} else { | |
console.error(`FAILED ${fullName}: sadly, no screenshot could be taken.`); | |
} | |
} | |
}, | |
}); | |
afterEach(async () => { | |
currentScreenshot = await page.screenshot(); | |
}); | |
} else { | |
jest.setTimeout(120e3); | |
} |
@ajs139, Thank you, it is working
@ajs139 is it possible to use jest- circus test runner instead of jasmine? If you have any idea please help me.
@chandana-b - haven't had the chance to experiment with Jest Circus yet, hope you managed to find a solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@chandana-96, can you try this: