什么导致nil的未定义方法`form':当用红宝石黄瓜填写表格时NilClass(NoMethodError)

时间:2012-12-11 12:58:59

标签: ruby cucumber watir

我正在尝试使用ruby cucumber填写许多表单表单,我正在为nil获取未定义的方法`form':NilClass(NoMethodError)。在第一页上,它正确地填写表格,但在第二页上,我得到了错误消息。

代码

Then /^next page Licence Type: "(.*)", Licence Years: "(.*)", NCD: "(.*)"$/ do |licence_type, licence_years, ncd|
   step 'I wait "1" seconds'
   frame = @browser.frames.find{ |frame| frame.form(:action => "Default.aspx?Action=nav&Page=5047").exists? }
   frame.form(:action => "Default.aspx?Action=nav&Page=5047").select(:id => "ctl03_content-216088_drivinglicencetype-213533_dd").select licence_type
   frame.form(:action => "Default.aspx?Action=nav&Page=5047").select(:id => "ctl03_content-216088_drivinglicenceyears-213534_dd").select licence_years
   frame.form(:action => "Default.aspx?Action=nav&Page=5047").select(:id => "ctl03_content-216088_ncd-for-new-models-767231_dd").select ncd
   frame.form(:action => "Default.aspx?Action=nav&Page=5047").select(:id => "ctl03_content-216088_nrofclaims-213540_dd").select "None"
   frame.form(:action => "Default.aspx?Action=nav&Page=5047").select(:id => "ctl03_content-216088_nrofconvictions-220190_dd").select "None"
   frame.form(:action => "Default.aspx?Action=nav&Page=5047").radio(:id => "ctl03_content-216088_usualpaymentmethod-231551_rbRadioList_0").click
   frame.form(:action => "Default.aspx?Action=nav&Page=5047").button(:id => "ctl03_navigation-216089_table-261670_row-261671_next-261674_next-261675_pbNext").click
   step 'I wait "1" seconds'
end


Then /^next page 2 Mileage: "(.*)", Car Value: "(.*)" & Overnight Location: "(.*)"$/ do |mileage, car_value, overnight_location|
  frame = @browser.frames.find{ |frame| frame.form(:method => "post").exists? }
  frame.form(:action => "Default.aspx?Action=nav&Page=5322").select(:id => "ctl03_content-231405_car-details-231421_annualmileage-231427_dd").select mileage
  frame.form(:action => "Default.aspx?Action=nav&Page=5322").text_field(:id => "ctl03_content-231405_car-details-231421_vehiclevalue-231426_tb").set car_value
  frame.form(:action => "Default.aspx?Action=nav&Page=5322").text_field(:id => "ctl03_content-231405_car-details-231421_purchase-date-231428_MONTH").set "01"
  frame.form(:action => "Default.aspx?Action=nav&Page=5322").text_field(:id => "ctl03_content-231405_car-details-231421_purchase-date-231428_YEAR").set "2008"
  frame.form(:action => "Default.aspx?Action=nav&Page=5322").select(:id => "ctl03_content-231405_car-details-231421_garage-231424_dd").select overnight_location
  frame.form(:action => "Default.aspx?Action=nav&Page=5322").button(:id => "ctl03_navigation-231432_copy-of-table-261677_row-261678_next-261681_next-261682_pbNext").click
  step 'The page Assumptions containing the following text'
  frame.form(:action => "post").button(:id => "ctl03_navigation-279445_copy-of-copy-of-table-279454_row-279455_next-279458_next-279459_pbNext").click
  step 'I wait "1" seconds'
  price =  frame.form(:action => "Default.aspx?Action=nav&Page=5334").div(:id, "premiumprice-882008").exist?
  puts price
  puts assert price.eql? (true)
end

1 个答案:

答案 0 :(得分:0)

您收到该错误是因为framenil - 它无法找到带有:method => "post"表单的框架。也许您应该按照第一个示例中的操作:action => "Default.aspx?Action=nav&Page=5322"查找表单。或者您可能需要在查找之前添加等待步骤 - 这些是我可以看到的与您的工作示例的唯一区别。

此外,我强烈建议您将表单分配给变量,这样就不会重复frame.form(:action => "Default.aspx?Action=nav&Page=5047")等等 - yuk!