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!

4

2 回答 2

0

这是我的错误。为此表示歉意!允许使用带插值的符号,问题在于我使用 upto 循环的方式。

对不起!

于 2012-07-03T13:59:35.903 回答
0

我没有尝试过符号插值,但字符串插值应该可以工作。但是,你很多人不需要这样做......通常,这种事情可以通过使用部分更紧密地建模你的网站来解决。elements您可以使用将创建元素数组的orsections方法来代替动态创建元素。这是我根据您给出的示例所做的:

我从您的示例中猜测您的网站列出了乘客......如果每个乘客都显示在一个单独的 div 中,那么您可以考虑以下内容:

#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

鉴于上述情况,您可以将乘客列表称为数组:

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

我不知道这是否有帮助,或者您的网站是否有可能,但它可能会为您指明正确的方向......

于 2012-07-03T14:01:27.487 回答