class CukeParser::ReportEngine::HomePage

Public Class Methods

new(utils,cuke_metrics) click to toggle source
# File lib/report_engine/home_page.rb, line 5
def initialize(utils,cuke_metrics)
        @utils = utils
        @cuke_metrics = cuke_metrics
end

Public Instance Methods

create_home_page(cuke,output_dir,title) click to toggle source
# File lib/report_engine/home_page.rb, line 180
def create_home_page(cuke,output_dir,title)
        output = File.new(output_dir+"/home_page.html","w+")
        builder = Nokogiri::HTML::Builder.new do |doc|
                doc.html{
                        doc.link(:href => "assets/stylesheets/bootstrap.css", :rel => "stylesheet")
                        doc.link(:href => "assets/stylesheets/cuke_parser.css", :rel => "stylesheet")
                        doc.script(:src => "assets/javascripts/bootstrap.js", :type => "text/javascript")
                        doc.script(:src => "assets/javascripts/jquery.js", :type => "text/javascript")
                        doc.script(:src => "http://code.highcharts.com/highcharts.js", :type => "text/javascript")
                        doc.script(:src => "http://code.highcharts.com/modules/exporting.js", :type => "text/javascript")
                        doc.body{
                                doc.h1({:class => "fancy-header"},title + " Statistics")
                                doc.div(:class => "container") {
                                        doc.div({:class => "row-fluid"}) {
                                                doc.div({:class => "span6",:id => "scenario-chart",:style => "width:45%; height:300px;"}) {
                                                        scenario_chart(doc)
                                                }
                                                doc.div({:class => "span6",:id => "step-chart",:style => "width:45%; height:300px;"}) {
                                                        step_chart(doc)
                                                }
                                        }
                                        doc.div(:class => "row-fluid") {
                                                doc.div(:class => "span12") {
                                                        cuke_statistics_table(cuke,doc)               
                                                }
                                        }
                                }
                        }
                }
        end
        output.puts builder.to_html
end
cuke_statistics_table(cuke,doc) click to toggle source
# File lib/report_engine/home_page.rb, line 10
def cuke_statistics_table(cuke,doc)
        doc.table(:class => "table table-bordered table-condensed neutral") {
                doc.thead {
                        doc.tr {
                                doc.th()
                                doc.th({:colspan => 3, :padding => "5px",},"Scenarios")
                                doc.th({:colspan => 4, :align => "center"},"Steps")
                                doc.th()
                                doc.th()
                        }
                        doc.tr {
                                doc.th("Feature")
                                doc.th("Total")
                                doc.th("Passed")
                                doc.th("Failed")
                                doc.th("Total")
                                doc.th("Passed")
                                doc.th("Failed")
                                doc.th("Skipped")
                                doc.th("Duration")
                                doc.th("Status")
                        }
                }
                cuke.features.each do |feature|
                        doc.tr(@utils.model_status_display(feature.status)) {
                                doc.td{
                                        doc.a({:href => "features/"+feature.name+".html"},(feature.name))
                                }
                                doc.td(@cuke_metrics[feature.name.to_sym][:feature_metrics][:scenario_count])
                                doc.td(@cuke_metrics[feature.name.to_sym][:feature_metrics][:passed])
                                doc.td(@cuke_metrics[feature.name.to_sym][:feature_metrics][:failed])
                                doc.td(@cuke_metrics[feature.name.to_sym][:scenario_metrics][:step_count])
                                doc.td(@cuke_metrics[feature.name.to_sym][:scenario_metrics][:passed])
                                doc.td(@cuke_metrics[feature.name.to_sym][:scenario_metrics][:failed])
                                doc.td(@cuke_metrics[feature.name.to_sym][:scenario_metrics][:skipped])
                                doc.td(@utils.time_to_words(feature.duration))
                                doc.td {
                                        doc.span(feature.status)
                                }                                
                        }
                end
                doc.tr {
                        doc.td(cuke.features.count)
                        doc.td(@cuke_metrics[:scenarios_passed_total] + @cuke_metrics[:scenarios_failed_total])
                        doc.td(@cuke_metrics[:scenarios_passed_total])
                        doc.td(@cuke_metrics[:scenarios_failed_total])
                        doc.td(@cuke_metrics[:steps_passed_total] + @cuke_metrics[:steps_failed_total] + @cuke_metrics[:steps_skipped_total])
                        doc.td(@cuke_metrics[:steps_passed_total])
                        doc.td(@cuke_metrics[:steps_failed_total])
                        doc.td(@cuke_metrics[:steps_skipped_total])
                        doc.td(@utils.time_to_words(cuke.duration))
                        doc.td("Totals")
                }
        }
end
scenario_chart(doc) click to toggle source
# File lib/report_engine/home_page.rb, line 125
def scenario_chart(doc)
        doc.script(
                "$(function () {
                    $('#scenario-chart').highcharts({
                        chart: {
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false
                        },
                        title: {
                            text: 'Scenarios',
                            style: {fontWeight: 'bold',
                                                                   fontSize: '20px'
                                                            }
                        },
                        tooltip: {
                               pointFormat: '<b>{point.percentage:.1f}%</b>'
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true,
                                    color: '#000000',
                                    connectorColor: '#000000',
                                    style: {
                                                                   fontSize: '13px'
                                                                   },
                                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                                }
                            }
                        },
                        series: [{
                            type: 'pie',
                            name: 'Scenario Metrics',
                            data: [
                                {  name: 'Passed',
                                   y: #{@cuke_metrics[:scenarios_passed_total]},
                                   color: '#46A546'
                                },
                                {
                                    name: 'Failed',
                                    y: #{@cuke_metrics[:scenarios_failed_total]},
                                    sliced: true,
                                    selected: true,
                                    color: 'red'
                                },
                            ]
                        }]
                    });
                });"
        )
end
step_chart(doc) click to toggle source
# File lib/report_engine/home_page.rb, line 66
def step_chart(doc)
        doc.script(
                "$(function () {
                    $('#step-chart').highcharts({
                        chart: {
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false
                        },
                        title: {
                            text: 'Steps',
                            style: {fontWeight: 'bold',
                                                                   fontSize: '20px'
                                                            }
                        },
                        tooltip: {
                               pointFormat: '<b>{point.percentage:.1f}%</b>'
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true,
                                    color: '#000000',
                                    connectorColor: '#000000',
                                    style: {
                                                                   fontSize: '13px'
                                                                   },
                                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                                }
                            }
                        },
                        series: [{
                            type: 'pie',
                            name: 'Step Metrics',
                            data: [
                                           {   name: 'Skipped',
                                                  y: #{@cuke_metrics[:steps_skipped_total]},
                                                  color: 'blue'
                                          },
                                {  name: 'Failed',
                                   y: #{@cuke_metrics[:steps_failed_total]},
                                   color: 'red',
                                  sliced: true,
                                   selected: true,
                                },
                                {
                                    name: 'Passed',
                                    y: #{@cuke_metrics[:steps_passed_total]},
                                    color: '#46A546'
                                },
                            ]
                        }]
                    });
                });"
        )
end