概要

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(); } };

推奨コンテンツ