【发布时间】:2018-03-15 20:15:53
【问题描述】:
我正在使用 Ruby、RSpec、Watir 等。我是新手。我需要使用不同的数据集运行规范。我曾经在 Selenium 中从 excel 表中读取数据或通过 xml 传递数据。我该怎么做?
【问题讨论】:
标签: ruby rspec data-driven-tests
我正在使用 Ruby、RSpec、Watir 等。我是新手。我需要使用不同的数据集运行规范。我曾经在 Selenium 中从 excel 表中读取数据或通过 xml 传递数据。我该怎么做?
【问题讨论】:
标签: ruby rspec data-driven-tests
您仍然可以从 excel 或 xml 中读取数据并将其作为实例变量保存在您的规范文件中。
使用nokogirigem:
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
您可以使用CSS 和XPath 查询解析存储在data 变量中的Nokogiri::XML::Document。阅读更多关于nokogiri api here。
【讨论】: