2017-09-04 8 views
0

異なるビューポートのデスクトップ/モバイル用にキュウリスイートを実行する場合、実行時に機能名またはシナリオ名の前にENV [VIEWPORT]シナリオが失敗したビューポートをHTMLレポートに表示することができます。私はすべてのビューポートレポートをマージする統一HTMLレポートを生成しています。上記のENVフラグに基づいて各シナリオを実行できますので、ビューポートによるシナリオのタグ付けは不要です。キュウリのシナリオ名/機能名またはタグをランタイムに前に追加する/

答えて

0

カスタムフォーマット用のカスタムフォーマッタを実装する必要があります。 キュウリ2.4.0バージョンとバンドラを想定https://github.com/moredip/timestamped-scenariosと同様そして

https://github.com/cucumber/cucumber/wiki/Custom-Formatters

は、使用される:

フォーマッタ

# features/support/viewport_aware/adds_viewport.rb 
require 'rubygems' 

module ViewportAware 
    module AddsViewport 
    def self.formatter_with_viewport(formatter_class) 
     Class.new(formatter_class){ include AddsViewport } 
    end 

    def scenario_name(keyword, name, file_colon_line, source_indent) 
     super(keyword, with_viewport(name), file_colon_line, source_indent) 
    end 

    def feature_name(keyword, name) 
     super(with_viewport(keyword), name) 
    end 

    # for json formatter 
    def on_finished_testing(event) 
     @feature_hashes.each do |it| 
     it[:name] = with_viewport(it[:name]) 
     (it[:elements] || []).each do |el| 
      el[:name] = with_viewport(el[:name]) 
     end 
     end 
     super 
    end 

    private 

    def with_viewport(str) 
     "#{str} <<#{ENV['VIEWPORT']}>>" 
    end 
    end 
end 

プリティフォーマッタ

# features/support/viewport_aware/pretty_formatter.rb 

require 'cucumber/formatter/pretty' 
module ViewportAware 
    PrettyFormatter = AddsViewport.formatter_with_viewport(Cucumber::Formatter::Pretty) 
end 

HTMLフォーマッタ

# features/support/viewport_aware/html_formatter.rb 

require 'cucumber/formatter/html' 
module ViewportAware 
    HtmlFormatter = AddsViewport.formatter_with_viewport(Cucumber::Formatter::Html) 
end 

JSONフォーマッタ

# features/support/viewport_aware/json_formatter.rb 

require 'cucumber/formatter/json' 
module ViewportAware 
    JsonFormatter = AddsViewport.formatter_with_viewport(Cucumber::Formatter::Json) 
end 

次に実行します。

VIEWPORT=mobile bundle exec cucumber -f ViewportAware::PrettyFormatter 

または

VIEWPORT=mobile bundle exec cucumber -f ViewportAware::HtmlFormatter 

かきれいなフォーマットの結果

VIEWPORT=mobile bundle exec cucumber -f ViewportAware::JsonFormatter 

Feature <<mobile>>: Create a boat 
    In order to avoid mistakes when finding my boat 
    As a sailor of my boat 
    I want to be told the details of my boat 

    Scenario: Creating a new boat <<mobile>>        
    <skimmed> 

またはJSONフォーマッタ:

[ 
    { 
    "uri": "features/add.feature", 
    "id": "create-a-boat", 
    "keyword": "Feature", 
    "name": "Create a boat <<mobile>>", 
    "description": " In order to avoid mistakes when finding my boat\n As a sailor of my boat\n I want to be told the details of my boat", 
    "line": 1, 
    "elements": [ 
     { 
     "id": "create-a-boat;creating-a-new-boat", 
     "keyword": "Scenario", 
     "name": "Creating a new boat <<mobile>>", 
+0

ありがとう@eugene。そりゃ素晴らしい。私はこれをテストし、それはHTMLとPrettyで動作しましたが、JSONでは動作しませんでした。どのようにしてJSONフォーマッタで動作させることができますか?私は上記のような定数を追加しようとしましたが、jsonフォーマッタが少し違って動作するように見えます。 – Rahul

+0

私は答えを拡張しました。 削除された「初期化」に注意してください。 このパッチは厄介になりました(そして、より厳格な猿のパッチのようになりました)が、まだ動作しています。 リファクタリングすることもできます。 –

+0

ありがとう@eugene。期待どおりに動作します。 – Rahul

関連する問題