Skip to content

Commit

Permalink
feat(suite): save suiteName in the output json
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jan 30, 2017
1 parent bb6924f commit 1b76ed9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The saved JSON file will have the following properties (see

```
title - the name of the test
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
Expand All @@ -58,6 +59,7 @@ and each test command before the test are recorded
```json
{
"title": "loads the About tab",
"suiteName": "Website",
"testName": "Website loads the About tab",
"testError": "Timed out retrying: Expected to find content: 'Join Us' but never did.",
"testCommands": [
Expand All @@ -71,7 +73,7 @@ and each test command before the test are recorded
"contains Join Us",
"assert expected **body :not(script):contains(**'Join Us'**), [type='submit'][value~='Join Us']** to exist in the DOM"
],
"screenshot": "opens-login.png"
"screenshot": "loads-the-about-tab.png"
}
```

Expand Down
27 changes: 23 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ const reject = require('lodash.reject')

const cleanupFilename = s => kebabCase(deburr(s))

function writeFailedTestInfo ({title, testName, testError, testCommands,
screenshot}) {
const info = {title, testName, testError, testCommands, screenshot}
function writeFailedTestInfo ({
title, suiteName, testName,
testError, testCommands, screenshot}) {
const info = {
title,
suiteName,
testName,
testError,
testCommands,
screenshot
}
const str = JSON.stringify(info, null, 2) + '\n'
const cleaned = cleanupFilename(testName)
const filename = `failed-${cleaned}.json`
Expand Down Expand Up @@ -98,6 +106,9 @@ function onFailed () {
cy.screenshot(screenshotName)
cy.wait(1000)

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

const testError = this.currentTest.err.message
// when running with UI, there are currentTest.commands
// otherwise just use whatever we have recorded ourselves
Expand All @@ -113,6 +124,9 @@ function onFailed () {

console.log('=== test failed ===')
console.log(title)
if (suiteName) {
console.log('suite', suiteName)
}
console.log(testName)
console.log('=== error ===')
console.log(testError)
Expand All @@ -121,7 +135,12 @@ function onFailed () {
console.log('=== screenshot ===')
console.log(screenshot)
writeFailedTestInfo({
title, testName, testError, testCommands, screenshot
title,
suiteName,
testName,
testError,
testCommands,
screenshot
})
}

Expand Down
2 changes: 2 additions & 0 deletions test/verify-failed-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function checkJsonFile (filename) {
la(is.object(result), 'expected an object from', jsonFilename, result)

la(is.unemptyString(result.title), 'missing test title', result)
la(is.unemptyString(result.suiteName), 'missing suite name', result)

la(is.unemptyString(result.testError), 'missing test error', result)
la(is.strings(result.testCommands), 'missing test commands', result)
la(result.testCommands[0].startsWith('visit'),
Expand Down

0 comments on commit 1b76ed9

Please sign in to comment.