Slack 報告器
概述
Slack 整合可讓您直接在團隊的 Slack 頻道中查看 Nightwatch.js 測試結果。
組態設定
步驟 1:安裝 Nightwatch-Slack-Reporter
在您的 nightwatch 專案中安裝 nightwatch-slack-reporter
作為相依性。
npm i nightwatch-slack-reporter --save-dev
步驟 2:Slack 應用程式設定
為了將 nightwatch-slack-reporter 與 Slack 整合,您需要設定一個傳入的 webhook 來傳送訊息。在 Slack 上建立應用程式後,您將取得一個 slack_webhook_url 來與 Slack 互動。如需更多資訊,您可以參考 Slack webhook 指南。
您必須依照步驟設定應用程式
導覽至 網址,然後按一下 建立您的 Slack 應用程式 按鈕
按一下 建立新應用程式 按鈕後,按一下 從頭開始。
為應用程式提供適當的名稱,選取一個 Slack 工作區,然後點擊 建立應用程式 按鈕。
注意: 在此步驟中,您可能會遇到下列錯誤,只有 Slack 管理員才能解決。
現在選取 傳入的 Webhook
將 啟用傳入的 webhook 按鈕切換為 開啟
然後按一下 將新的 Webhook 新增至工作區
選取一個頻道,然後按一下 允許 按鈕來授權它
這樣就完成了,您的 webhook 網址已準備好使用
步驟 3. 將報告器與 Nightwatch 整合
nightwatch-slack-reporter
需要一個選項物件,其中將包含 slack_message 和 slack_webhook_url。您可以根據需要將 slack_message 設定為函式或訊息,也可以設定您在 步驟 2 中建立的 slack_webhook_url 值
透過 globals.js 檔案
請確定您的 globals.js
已設定完成;如果沒有,請依照 設定指南。
const options = {
// function or message string
slack_message: function(results, options) {
// Message payload or string
return {
text: 'Test completed, passed ' + results.passed + ', failed ' + results.failed,
username: 'Nightwatch',
icon_emoji: ':ghost:'
}
},
// This can be specified with SLACK_WEBHOOK_URL environment variable
slack_webhook_url: 'https://hooks.slack.com/services/...'
}
module.exports = {
reporter: (require('nightwatch-slack-reporter')(options))
}
透過設定檔
const options = {
slack_message: function(results, options) {
return {
text: 'Test completed, passed ' + results.passed + ', failed ' + results.failed,
username: 'Nightwatch',
icon_emoji: ':ghost:'
}
},
slack_webhook_url: 'https://hooks.slack.com/services/...'
}
module.exports = {
src_folders: ['tests'],
globals: {
reporter: (require('nightwatch-slack-reporter')(options)),
},
// Other stuff
}
範例
步驟 0:安裝 Nightwatch
步驟 1:執行範例測試
考慮 duckDuckGo.js
範例測試
describe('duckduckgo example', function() {
it('Search Nightwatch.js and check results', function(browser) {
browser
.navigateTo('https://duckduckgo.com')
.waitForElementVisible('#search_form_input_homepage')
.sendKeys('#search_form_input_homepage', ['Nightwatch.js'])
.click('#search_button_homepage')
.assert.visible('.results--main')
.assert.textContains('.results--main', 'Nightwatch.js');
});
});
您不需要做任何額外的事情,因為您已將 Slack 報告器設定為全域。像往常一樣執行測試
npx nightwatch examples/tests/duckDuckGo.js --env chrome