Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

In this tutorial, we will create some tests in Ruby using RSpec and the rspec_junit_formatter gem.

The tests make use of Selenium, with the watir gem.

Requirements

  • Install the rspec, watir and rspec_junit-formatter

No Format
gem install rspec watir rspec_junit_formatter


  • Selenium server must be installed and running.

Description


Code Block
languageruby
require 'rspec'
require 'watir'

browser = Watir::Browser.new

RSpec.configure do |config|
  config.before(:each) { @browser = browser }
  config.after(:suite) { browser.close unless browser.nil? }
end
describe "a simple demonstration of watir and trad RSpec" do
  before(:each) do
    @browser.goto("https://cukes.info/")
  end
  describe "that we have hit a valid URL" do
    it "should not return an invalid error message" do
      @browser.text.should_not include('The requested URL could not be retrieved')
    end
   end
  describe "the contents of the cukes page" do # the describe() is an example group
    it "should include aidy's name" do # the it() represents the detail that will be expressed in the code within the block
      @browser.text.should include('Aidy Lewis')
    end
    it "should not include the great Nietchzche's name" do
      @browser.text.should_not include('Frederick Nietchzche')
    end
  end
end


After running the tests and generating the JUnit XML report (e.g., rspec.xml), it can be imported to Xray (either by the REST API or through Import Execution Results action within the Test Execution).

No Format
rspec -c watir_sample.rb --format RspecJunitFormatter --out rspec.xml


JUnit's Test Case is mapped to a Generic Test in Jira, and the Generic Test Definition field contains the name of the spec file concatenated with the several "describe"' that make up the test case.

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the name of the created JUnit XML report file.


References