-1

I'm using Ruby, RSpec, Watir, etc. I'm a newbie at it. I need to run a spec with different sets of data. I used to to this in Selenium reading the data from an excel sheet or passing the data through an xml. How do I do it here?

1 Answers1

0

You can still read the data from excel or xml and save it as an instance variable in your spec file.

Using nokogiri gem:

require 'nokogiri'

RSpec.describe 'Your Feature' do
  context 'Using dataset 1', :dataset1 do
    let :data do
      File.open('dataset1.xml') { |f| Nokogiri::XML(f) }
    end

    it 'test with dataset 1' do
      # describe your test here
      puts data  # data returns a Nokogiri::XML::Document object
    end
  end

  context 'Using dataset 2', :dataset2 do
    let :data do
      File.open('dataset2.xml') { |f| Nokogiri::XML(f) }
    end

    it 'test with dataset 2' do
      # describe your test here
      puts data  # data returns a Nokogiri::XML::Document object
    end
  end
end

You can parse the Nokogiri::XML::Document that is stored in the data variable by using CSS and XPath queries. Read more about nokogiri api here.

Igor-S
  • 655
  • 8
  • 10