2016-09-01 29 views

回答

0

所以有兩種方法可以嘗試。 1是編寫自己的格式化程序。我還沒有嘗試過,但這將是我的下一個項目。 第二種方法是從After Hook部分的場景對象中破解您關心的所有字段。 我已經爲黃瓜的2.0版本做了這個。當我查看Post-2.0時,該對象似乎並不公開所有我想要的數據,我認爲這是Pretyface gem仍未更新到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

可以定義hook每個場景寫入到數據庫後執行。我曾與sequel寶石數據庫連接,但也有很多其他人。

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

寫出到數據庫不是問題。從運行中提取所需的所有數據。我找到了兩種方法,一旦我有一切工作和清理,我會在這裏發佈。但簡短的答案與您發佈的內容類似。需要一些黑客來獲取所有數據。 –

相關問題