Search code examples
rubyrspecrakecapybaraeasyhtmlreport

Rspec, capybara, rake - can't create HTML report


I want do smoke test for my web page.

Test work correct.

After each test I have html report, but only if start test single(each test have diff pass and login) html report in .rspec file

--format html

--out rspec_results.html

I create Rake task for start all test together with auto take password.

Rake task code:

namespace :smoke do

  users = [

    {login: "login",     pass: "pass", tag: "role1"    },
    {login: "login",     pass: "pass", tag: "role2"    },
    {login: "login",     pass: "pass", tag: "role3"    },
    {login: "login",     pass: "pass", tag: "role4"    },
    {login: "login",     pass: "pass", tag: "role5"    }, 
    {login: "login",     pass: "pass", tag: "role6"    },
    {login: "login",     pass: "pass", tag: "role7"    },
    {login: "login",     pass: "pass", tag: "role8"    } 


  ] 

  users.each do |user|

    desc "smoke test for admin"

    task "#{user[:tag].to_sym}" => :environment do
        task('spec').clear

      ENV['LOGIN']    = user[:login]
      ENV['PASSWORD'] = user[:pass]

      RSpec::Core::RakeTask.new(:spec) do |t|
        t.pattern    = './spec/smoke/**/*'
        t.rspec_opts = "-t #{user[:tag]}" 
        t.fail_on_error = false
      end 
      Rake::Task["spec"].execute 
    end
  end

  desc "smoke test for all users"
  task all: :environment do
    task('spec').clear

    Rake::Task["smoke:role1"].invoke
    Rake::Task["smoke:role2"].invoke
    Rake::Task["smoke:role3"].invoke
    Rake::Task["smoke:role4"].invoke
    Rake::Task["smoke:role5"].invoke
    Rake::Task["smoke:role6"].invoke
    Rake::Task["smoke:role7"].invoke
    Rake::Task["smoke:role8"].invoke

  end

I try add this t.rspec_opts = '--format html --out reports/rspec_results.html'

If I choose one role

Example:

rake smoke:role1 (it's start test for role1)

After that, continue test for another role, but use pass and login from role1, respectively all another test fail. and in report I have all test, but only first step pass correctly another fail.

How I can do report for my rake tasks, and if somebody know how add screen(capybara) to this report if step from test fail.

Regards.


Solution

  • Do you try to change:

    RSpec::Core::RakeTask.new(:spec) do |t|
      t.pattern       = './spec/smoke/**/*'
      t.rspec_opts    = "-t #{user[:tag]}" 
      t.fail_on_error = false
    end
    

    to:

    RSpec::Core::RakeTask.new(:spec) do |t|
      t.pattern       = './spec/smoke/**/*'
      t.rspec_opts    = "-t #{user[:tag]} --format html --out reports/rspec_results_#{user[:login]}.html" 
      t.fail_on_error = false
    end
    

    It will create a reports for each user: rspec_results_admin.html for rake smoke:admin etc.