我使用Slack將量角器測試掛鉤,如果測試開始並且一旦完成,想法是在鬆弛室中發送消息。Slack集成僅適用於onPrepare,但不適用於onLinunch後的onComplete?
但是,我只能在onPrepare期間成功地發送消息給slack。但不是在afterLanch或甚至在onComplete。
我試圖在afterLaunch和onComplete中做一個簡單的console.log,所以我知道它的工作原理。唯一讓我感到困惑的是爲什麼在測試完成之後,它並沒有將信息發送給我們。
如果有更好的方法來做到這一點,請告訴我你的想法。現在,這是我擁有的最好的。
請看看我的代碼:
let SpecReporter = require('jasmine-spec-reporter').SpecReporter;
var webRep = require('jasmine-slack-reporter');
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
var SlackWebhook = require('slack-webhook');
var slack = new SlackWebhook('my-webhook-url');
exports.config = {
capabilities: {
'browserName' : 'chrome',
},
seleniumAddress: 'http://localhost:4446/wd/hub',
specs: ['./smoke-test/loginAccountType.js'],
onPrepare: function() {
browser.ignoreSynchronization = true,
slack.send({
text: "Test is starting",
channel: '#test-report'
}),
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
}
})),
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: './reports',
takeScreenshotsOnlyOnFailures: true,
})
);
},
afterLaunch: function() {
slack.send({
text: "Test is Done",
channel: '#test-report'
})
},
jasmineNodeOpts: {
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 100000,
print: function() {},
},
};