[code language=”ruby”]
RSpec.describe ‘search’, type: :feature, js: true do
context ‘collect ids of items’ do
describe "location" do

it "Collecting ids of listings" do
visit("https://www.xploralab.com?q=query")
expect(page.status_code).to eq(200)

ids = []

(1..50).each do |p|
begin
expect(page.status_code).to eq(200)
puts "Processing page" + p.to_s
all(‘a.space’).each { |a|
puts "processing link" + a[:href].to_s
if a[:href].include? "/id_matcher1"
ids << a[:href].split("id_matcher1")[1].split("?")[0]
elsif a[:href].include? "/id_matcher2"
ids << a[:href].split("/id_matcher1")[1].split("?")[0]
end
}
begin
find("#pager ul li.next a").click
rescue => e
puts "X"*100
puts e
end
expect(page.status_code).to eq(200)
rescue
break
end
end
puts "writing to a csv"
CSV.open("listings.csv", "wb") do |csv|
csv << ["Order Number", "Listing ID"]
ids.each_with_index do |data, index|
csv << [index, data]
end
end

end
end
end
end
[/code]