2016-09-01 18 views
0

私はPageObjectsでCucumber/Watir/Rubyスタックを使用しています。 私は、pretyface gemのようなpretyレポートを作成するのではなく、すべてのテスト結果をデータベースに保存したいと考えています。 誰でもこれをしましたか?Cucumber/Watir/Rubyのテスト結果をデータベースに書き込む良い方法はありますか?

はあなたが各シナリオでは、データベースへの書き込み後に実行するhookを定義することができ、あなたに

答えて

0

したがって、2つのアプローチがあります。 1は独自のフォーマッタを書くことです。私はこれをまだ試みていないが、それは私の次のサイドプロジェクトになるだろう。 2番目の方法は、After Hookセクションのシナリオオブジェクトから気になるすべてのフィールドをハックすることです。 私はキュウリのプレ2.0バージョンでこれを行っています。 Post-2.0を見ると、オブジェクトは私が望むすべてのデータを公開しているようには見えません.Pretyfaceの宝石がまだ1.9.3ほども更新されていない理由の一部です。 以下のコードはあまり綺麗ではありませんが、動作します。 After Hooksメソッドから呼び出すだけです

def read_and_export_scenario_results(scenario) 
    set1 = scenario.instance_variable_get(:@current_visitor) 

    feature_loc = scenario.feature.location 
    feature_name = scenario.feature.title 
    feature_desc = scenario.feature.description 
    scenario_name = scenario.title 
    profile = set1.configuration.options.send(:profiles)[0] 
    #get data from Listeners 

    results_loc = set1.configuration.options.send(:expanded_args)[set1.configuration.options.send(:expanded_args).size-1] 
    run = results_loc.split('/')[2] 

    steps = Array.new(set1.runtime.results.steps.count) 
    i=0 
    set1.runtime.results.steps.each do |step| 
     step_hash = Hash.new 
     step_hash['StepName'] = step.name 
     step_hash['ReportedException'] = step.reported_exception 
     step_hash['Status'] = step.status 
     step_hash['Message'] = step.multiline_arg 
     steps[i] = step_hash 
     i += 1 
    end 

    if scenario.failed? 
    pic_dir = 'screenshots' 
    pic_name = "ERR_#{run}_#{@current_page.class}_#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}.png" 
    pic_src = "#{pic_dir}\\#{pic_name}" 

    unless File.directory?(pic_dir) 
     Dir.mkdir(pic_dir) 
    end 

    @current_page.save_screenshot(pic_src) 
    embed(pic_src, 'image/png') 
    else 
    pic_src = '' 
    end 
    sql_object = Sql.new 
    sql_load_scenario = "AddScenario '#{feature_loc}', '#{feature_name}', '#{feature_desc}', '#{scenario_name}', '#{profile}', '#{run}', '#{pic_src}', '#{results_loc}', '#{FigNewton.application}', '#{FigNewton.base_location}'" 
    feature_ID = sql_object.execute_query(sql_load_scenario).to_a[0] 
    steps.each do |step| 
    sql_load_steps = "AddScenarioStep #{feature_ID}, '#{step['StepName']}', '#{step['Status']}', '#{step['ReportedException']}', '#{step['Message']}'" 
    sql_object.execute_query(sql_load_steps) 
end 
0

ありがとうございます。私はデータベース接続のためにsequel gemで作業しましたが、他にも多くのものがあります。

After do |scenario| 
begin 
    //Get values for the scenario 
    scenario.name 
    scenario.failed? 
// <database code to add values> 
end 
end 
+0

DBに書き込むことは問題ではありません。私が実行したいすべてのデータを抽出することです。私は2つの方法を見つけました。私はすべてが働いてきれいになったらここに投稿します。しかし、短い答えはあなたが投稿したものと似ています。すべてのデータを取り出すために必要なハックがいくつかあります。 –

関連する問題