0

运行此程序时遇到问题,我不断收到错误 .rb:45:in <main>': undefined method heade'for DealerDetail:Class (NoMethodError) 我做错了什么我环顾四周,但找不到任何解决方案,我们将不胜感激

require 'watir-webdriver'

@browser = Watir::Browser.new

@page = [:dealerdetail => "www.google.com",
         :findadealer => "www.google.com",
         :findadealer_results => "www.google.com"
          ]

class DealerDetail 

 attr_accessor :browser   


 def heade

    @browser.goto @page [:dealerdetail]
    @browser.element(:id, 'mainNav').exists? 
        puts 'main navigation bar appears'

    puts 'navigation bar does not appear'

 end


 def footer   
    if @browser.element(:id, 'pageFooter').exists?
    puts 'footer  appears'
    elsif 
    puts 'Footer does not appear'
    end
  end

end


@deal = DealerDetail .new

@deal.heade
4

1 回答 1

0

heade method trying to access @page, which in not available inside instance cause you defined it outside the scope.

I suppose you want to define @page instance variable inside class:

require 'watir-webdriver'

class DealerDetail 

  attr_accessor :browser

  def initialize
    @browser = Watir::Browser.new

    @page = [:dealerdetail => "www.google.com",
      :findadealer => "www.google.com",
      :findadealer_results => "www.google.com"
    ]
  end

  def heade

    @browser.goto @page[:dealerdetail]
    @browser.element(:id, 'mainNav').exists? 
    puts 'main navigation bar appears'

    puts 'navigation bar does not appear'

  end

end

@deal = DealerDetail.new

@deal.heade

Also make sure you have no spaces between class/object and called method.

DealerDetail .new should be DealerDetail.new

@page [:dealerdetail] should be @page[:dealerdetail]

于 2012-12-04T13:03:16.340 回答