總覽

用於 Nightwatch.js 端對端測試框架的 TeamCity 格式器。其輸出可供其他工具使用以視覺化報告。

組態範例

步驟 0:安裝 Nightwatch

按照指南或觀看影片,從頭安裝 Nightwatch。

步驟 1:安裝 Nightwatch Teamcity 報告器

在您的 Nightwatch 專案中安裝nightwatch-teamcity作為依賴項。

npm i nightwatch-teamcity --save-dev

步驟 2:執行範例測試

考慮 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');
  }); 
});

您可以使用以下命令執行此測試

npx nightwatch examples/tests/duckDuckGo.js -–reporter node_modules/nightwatch-teamcity/index.js

您也可以在單獨的檔案 (例如:nightwatch-reporter.js) 中定義報告器,方法是包含以下程式碼,然後使用 --reporter cli 引數指定檔案的路徑。

const teamCityFormatter = require("nightwatch-teamcity").format;

module.exports = { reporter: (results,done)=>{ teamCityFormatter(results); done(); } };
npx nightwatch examples/tests/duckDuckGo.js --reporter ./nightwatch-reporter.js

步驟 3:檢視 JSON 報告

TeamCity 報告可以在主控台中看到,它看起來會像這樣

與其他報告器組合

為了與另一個報告器 (例如:nightwatch-html-reporter) 組合,您可以按照下方所示範例進行操作

nightwatch-reporter.js
const HtmlReporter = require("nightwatch-html-reporter");

const teamCityFormatter = require("nightwatch-teamcity").format;
const reporter = new HtmlReporter({ reportsDirectory: "./reports", });
module.exports = { write: function(results, options, done) { teamCityFormatter(results); reporter.fn(results, done); done(); } };

推薦內容