-3

我正在尝试使用 ruby​​ cucumber 填写一些表单,但我得到了 nil:NilClass (NoMethodError) 的未定义方法“form”。在第一页上,它正确填写了表格,但在第二页上,我收到了错误消息。

代码

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
4

1 回答 1

0

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

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

于 2012-12-11T13:40:31.050 回答