2017-07-04 7 views
0

私はNightwatch-Cucumberを使用してend2endテストを自動化し、テスト実行後にキュウリのhtmlレポートを作成する場合は、cucumber-html-reportercucumber-html-reporterNightwatch-Cucumberでcucumber-html-reporterを使用しているときにJSON入力が予期せず終了する

Unable to parse cucumberjs output into json: 'reports/cucumber.json' SyntaxError: reports/cucumber.json: Unexpected end of JSON input 
    at JSON.parse (<anonymous>) 
    at Object.readFileSync (/Users/GRme/projects/e2e-web-tests/node_modules/jsonfile/index.js:69:17) 

そして、私の生成cucumber.jsonが無効である理由を私は知りません。

私は次のバージョンを使用します。

require('nightwatch-cucumber')({ 
    cucumberArgs: [ 
     '--tags', '@run', 
     '--require', 'timeout.js', 
     '--require', 'hooks.js', 
     '--require', 'features/step_definitions', 
     '--format', 'pretty', 
     '--format', 'json:reports/cucumber.json', 
     'features'] 
}); 

そして、これは私のキュウリのHTMLレポートの生成が実行されhooks.js、次のとおりです:

"cucumber-html-reporter": "^2.0.0", 
"nightwatch": "^0.9.16", 
"nightwatch-cucumber": "^7.1.10", 

これはnightwatch.conf.jsで私のconfigです

const {client} = require('nightwatch-cucumber'); 
const {defineSupportCode} = require('cucumber'); 
var reporter = require('cucumber-html-reporter'); 

var options = { 
    theme: 'bootstrap', 
    jsonFile: 'reports/cucumber.json', 
    output: 'reports/cucumber_report.html', 
    reportSuiteAsScenarios: true, 
    launchReport: false, 
    //ignoreBadJsonFile: true, 
    name: 'NIKITA end2end tests', 
    brandTitle: 'NIKITA end2end tests', 
    storeScreenShots: true, 
    metadata: { 
// "App Version": "0.0.1", 
// "Test Environment": "AAT", 
// "Browser": "Chrome XXX", 
// "Platform": "Mac OS X", 
    } 
}; 

defineSupportCode(({Before, After}) => { 
    Before(function() { 
    client.maximizeWindow(); 
    }); 

    After(function() { 
    reporter.generate(options); 
    }); 
}); 

私の作成した、明らかに無効なcucumber.json成功Cucumber Reports Plugin実行してジェンキンス経由キュウリHTMLレポートを生成

[ 
    { 
    "keyword": "Feature", 
    "line": 1, 
    "name": "only a test feature", 
    "tags": [], 
    "uri": "/Users/GRme/projects/e2e-web-tests/features/testFeature.feature", 
    "elements": [ 
     { 
     "keyword": "Scenario", 
     "line": 4, 
     "name": "only a test Scenario", 
     "tags": [ 
      { 
      "line": 3, 
      "name": "@run" 
      } 
     ], 
     "id": "only-a-test-feature;only-a-test-scenario", 
     "steps": [ 
      { 
      "arguments": [], 
      "keyword": "Before", 
      "result": { 
       "status": "passed", 
       "duration": 1 
      }, 
      "hidden": true, 
      "match": { 
       "location": "/Users/GRme/projects/e2e-web-tests/hooks.js:24" 
      } 
      }, 
      { 
      "arguments": [], 
      "keyword": "When ", 
      "name": "\"1\" seconds waiting", 
      "result": { 
       "status": "passed", 
       "duration": 2615 
      }, 
      "line": 5, 
      "match": { 
       "location": "/Users/GRme/projects/e2e-web-tests/features/step_definitions/abstractStepDefinition.js:10" 
      } 
      }, 
      { 
      "arguments": [], 
      "keyword": "After", 
      "result": { 
       "status": "passed", 
       "duration": 4 
      }, 
      "hidden": true, 
      "match": { 
       "location": "/Users/GRme/projects/e2e-web-tests/hooks.js:28" 
      } 
      } 
     ] 
     } 
    ], 
    "id": "only-a-test-feature" 
    } 
] 

:次のようになります。

どのようにして私の問題を解決でき、どのフレームワーク(Nightwatch-Cucumberまたはcucumber-html-reporter)が原因ですか?生成された無効な部分は何ですか。cucumber.json

+0

投稿したJSONが有効です。ファイルをチェックして、BOM文字のような特別なものがないことを確認します。 – Barmar

+0

これは本当に問題の原因です。私は 'cucumber.json'をエディタに開いて保存し、それをBOMのないUTF-8ファイルとして保存しました。ですから問題はこのファイルを作成して書き込む 'Nightwatch-Cucumber'でなければなりません。これらのBOMをJavaScriptで確実に削除するにはどうすればよいですか?これを行うNode.jsライブラリはありますか? – Martin

答えて

0

Event Handlerを使用して問題を解決しました。私はイベントAfterFeaturesのためのそのようなイベントハンドラ関数にキュウリのレポートの世代を入れて、それは私にとって完璧に動作します。

詳細情報はhereです。

0

テスト実行の別のステップでキュウリのhtmlレポートを生成してください。たとえば、npmスクリプトを使用している場合、別のnpmスクリプトを使用してレポートを生成します。あなたのアプローチの問題は、Cucumber.jsのグローバルAfterフックでは、まだレポートが作成されていないということです。だからこそあなたはこのような誤りを抱えています。私は、cucumber-html-reporterを実行するために別のnode.jsスクリプトを使用することをお勧めします。

関連する問題