Question

I am getting the following error when I execute the below code.

Please let me know the way to execute the method 'startup' in Eclipse.

Error Message:

': undefined local variable or method ***startup***' for PageObjects:Class (NameError) from C:/Technical/RubyTraining/PageObjects.rb:1:in'

Code:

class PageObjects

require 'selenium-webdriver'

require 'page-object'


 def startup

   @browser = Selenium::WebDriver.for :firefox

   @browser.manage.window.maximize

 end

  startup


end
Was it helpful?

Solution

From the code you have provided, you don't need the class PageObjects (If you have more code, please post them all at once). So you might simply try this:

require 'selenium-webdriver'
# require 'page-object' # You are not using page-object either.

def startup
  @browser = Selenium::WebDriver.for :firefox
  @browser.manage.window.maximize
end

startup

However, if you want to use this class, you need to call this instance method setup outside your class after initializing the class. Like this:

class PageObjects
  require 'selenium-webdriver'
  require 'page-object'

   def startup
    @browser = Selenium::WebDriver.for :firefox
    @browser.manage.window.maximize
   end
end

PageObjects.new.startup
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top