Created
January 30, 2018 03:07
-
-
Save surfjedi/509c3751c8127a42034d8d79048a6bd6 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('dotenv').config(); | |
let SpecReporter = require('jasmine-spec-reporter').SpecReporter; | |
let jasmineReporters = require('jasmine-reporters'); | |
let request = require('request'); | |
var fs = require('fs'); | |
let gitHash; | |
exports.config = { | |
// NOTE: below is only needed if not using chrome with directConnect | |
// seleniumAddress: 'http://localhost:4444/wd/hub', | |
specs: [ | |
'e2e/login.js', | |
'e2e/*.e2espec.js' | |
], | |
// directConnect: true, | |
capabilities: { | |
'directConnect': true, | |
'browserName': 'chrome', | |
chromeOptions: { | |
args: process.env.E2EURL === 'http://localhost:3000/' ? [] : ["--headless", "--disable-gpu", "--window-size=1200x800"] | |
} | |
}, | |
params: { | |
sleep:process.env.SLEEP || 1000, | |
user: process.env.TEST_USER, | |
password: process.env.PASSWORD, | |
url: process.env.E2EURL, | |
provider: process.env.PROVIDER || 'HIS' | |
}, | |
jasmineNodeOpts: { | |
showColors: true, | |
defaultTimeoutInterval: 120000, | |
includeStackTrace : false, | |
isVerbose : false, | |
print: function () {} | |
}, | |
resultJsonOutputFile:'protractor-output.json', | |
beforeLaunch:()=>{ | |
require('child_process').exec('git rev-parse HEAD', (err, stdout)=> { | |
console.log('Last commit hash on this branch is:', stdout); | |
gitHash = stdout; | |
}); | |
}, | |
onPrepare: function () { | |
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({ | |
savePath: process.env.E2E_JUNIT, | |
consolidateAll: false | |
})); | |
jasmine.getEnv().addReporter(new SpecReporter({ | |
spec: { | |
displayStacktrace: false | |
} | |
})); | |
}, | |
// NOTE: may need this later | |
// onCleanUp:(number)=> { | |
// console.log('end', number); | |
// }, | |
afterLaunch:number => { | |
var contents = fs.readFileSync('protractor-output.json', 'utf8'); | |
return new Promise((resolve, reject) => { | |
let timestamp = new Date(); | |
let passing = { | |
'text': `${timestamp} E2E passed`, | |
'attachments': [ | |
{ | |
"fallback": `${process.env.E2EURL} All protractor tests passed. Git# of these tests ${gitHash}`, | |
"color" :"#36a64f", | |
"fields":[ | |
{ | |
"title":"URL", | |
"value":`${process.env.E2EURL}`, | |
"short":false | |
}, | |
{ | |
"title":"git #", | |
"value":`${gitHash}`, | |
"short":false | |
} | |
] | |
} | |
] | |
} | |
// Below are slack webhooks replace xxxxxx with your own url | |
let url = 'https://hooks.slack.com/services/xxxxx' | |
let alertUrl = 'https://hooks.slack.com/services/xxxxxxxx' | |
let failed={ | |
"text": `${timestamp} E2E FAILED OMG its getting real.`, | |
"attachments":[ | |
{ | |
// "fallback":"New open task [Urgent]: <http://url_to_task|Test out Slack message attachments>", | |
// "pretext":"New open task [Urgent]: <http://url_to_task|Test out Slack message attachments>", | |
"color":"#D00000", | |
"fields":[ | |
{ | |
"title":"URL", | |
"value":`${process.env.E2EURL}`, | |
"short":false | |
}, | |
{ | |
"title":"git #", | |
"value":`${gitHash}`, | |
"short":false | |
}, | |
{ | |
"title":"Results", | |
"value":contents, | |
"short":false | |
} | |
] | |
} | |
]}; | |
function cb(err, res, body) { | |
console.log(`Sent to Slack`); | |
resolve(); | |
} | |
let payload = number ? failed: passing | |
if(browser.params.url !== 'http://localhost:3000/') { | |
request.post({'url':url, 'body': JSON.stringify(payload)}, cb) | |
if(number) { | |
let alertPayload = { | |
"text": `${timestamp} E2E FAILED.`, | |
"attachments":[ | |
{ | |
// "fallback":"New open task [Urgent]: <http://url_to_task|Test out Slack message attachments>", | |
// "pretext":"New open task [Urgent]: <http://url_to_task|Test out Slack message attachments>", | |
"color":"#D00000", | |
"fields":[ | |
{ | |
"title":"URL", | |
"value":`${process.env.E2EURL}`, | |
"short":false | |
}, | |
{ | |
"title":"git #", | |
"value":`${gitHash}`, | |
"short":false | |
} | |
] | |
} | |
]}; | |
request.post({'url':alertUrl, 'body': JSON.stringify(alertPayload)}, cb) | |
} | |
} else { | |
resolve() | |
} | |
}) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment