0

do you happen to know if there is a way to define both elements and locators using string or symbol interpolation while using the site-prism gem?

I'm trying to do something like this:

0.upto(@adults) do  {
element :"adult#{index}", "#passenger-first-name-#{index}"
element :"adult#{index}", "#passenger-last-name-#{index}"
index+=1
}

But I'm getting the following syntax error at executing:

syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' (SyntaxError) element :"adult#{index}" , "#passenger-first-name-#{index}"

I was reading here that symbols DO allow interpolation: http://www.robertsosinski.com/2009/01/11/the-difference-between-ruby-symbols-and-strings/

Maybe I am missing something? Thanks a lot!

adids
  • 137
  • 12
  • Too bad the question was closed. It's exactly the situation I have right now (symbol interpolation) – ezuk Dec 27 '12 at 18:10

2 Answers2

0

It was my mistake. Sorry about this! It is alloweed to use symbols with interpolation, the issue was with the way I've used the upto loop.

Sorry!

adids
  • 137
  • 12
0

I haven't tried symbol interpolation, but the string interpolation should work. But, you many not need to do that... usually, this sort of thing can be solved by more closely modelling your website using sections. Instead of dynamically creating elements, you could use the elements or sections methods that will create arrays of elements. Here's what I'd do based the example you've given:

I'm guessing from your example that your website lists passengers... if each passenger is displayed in a separate div then you could consider something like:

#section that models a single passenger
class PassengerDetails < SitePrism::Section
  element :first_name, "input[id^=passenger-first-name]"
  element :last_name, "input[^=passenger-last-name]"
end

#page that contains a list of passengers
class FlightManifest < SitePrism::Page
  sections :passengers, PassengerDetails, ".passenger-details"
  #... where ".passenger-details" is a style on the divs that contains a passenger's details
end

Given the above, you could refer to the list of passengers as an array:

Then /^the flight manifest contains the correct first and last names for each passenger$/ do
  @flight_manifest.passengers.each_with_index do |passenger, i|
    passenger.first_name.text.should == @expected_passengers[i].first_name
    passenger.last_name.text.should == @expected_passengers[i].last_name
  end
end

I don't know if that helps, or if it's possible with your website, but it might point you in the right direction...

Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58