NoMethodError: undefined method

I am not able to understand why it gets nil object. would someone let me
know the solution ??

following are my classes and modules.
LoginTest.rb
require 'LoginPage'
include LoginPage
require 'BaseClass'
include BaseClass

require 'rubygems'
require 'watir'
require 'test\unit'
class LoginTest < Test::Unit::TestCase

  def test_login()
    username_textbox.set("Gaurang")
    password_textbox.set("gaurang")
    login_button.click()
  end

end

LoginPage.rb
module LoginPage
  def username_textbox
    return @browser.text_field(:id,"Email")
  end

  def password_textbox
    return @browser.text_field(:id,"Passwd")
  end

  def login_button
    return @browser.button(:id,"signIn")
  end
end

BaseClass.rb
module BaseClass
  def setup
    @browser = Watir::Browser.new
    @browser.goto("http://gmail.com")
    @browser.maximize
  end

end

Now when i run the LoginTest.rb it gives me following error.
NoMethodError: undefined method `text_field' for nil:NilClass

···

--
Posted via http://www.ruby-forum.com/.

Hi,

Do you initialize the instance variable @browser?
I think you need to call the method BaseClass.setup.

Please retry after rewriting the following code

def test_login()
   username_textbox.set("Gaurang")
   password_textbox.set("gaurang")
   login_button.click()
end

into

def test_login()
    setup() # Add this line
    username_textbox.set("Gaurang")
    password_textbox.set("gaurang")
    login_button.click()
end

Regards,

···

--
NOBUOKA Yu

Y. Nobuoka wrote in post #1013959:

Hi,

Do you initialize the instance variable @browser?
I think you need to call the method BaseClass.setup.

Please retry after rewriting the following code

def test_login()
   username_textbox.set("Gaurang")
   password_textbox.set("gaurang")
   login_button.click()
end

into

def test_login()
    setup() # Add this line
    username_textbox.set("Gaurang")
    password_textbox.set("gaurang")
    login_button.click()
end

Regards,

actually the some of method is of unit test and gets invoked
automatically. And sorry, as i have put the wrong code. the code is
something like this..
require 'rubygems'
require 'LoginPage'

gem 'test-unit'
require 'test/unit'
require 'BaseClass'

class LoginTest < Test::Unit::TestCase
    extend BaseClassClass
    include LoginPage

    def test_third()
      puts "third"
      username_textbox.set("gaurang")
    end
end

I am not including the BaseClass rather I am extending it.

···

--
Posted via http://www.ruby-forum.com/\.

So, show the *exact* error you are getting, together with the backtrace.
And point out the actual line of code where the exception is raised.

Also, try adding a 'puts "in setup"' into your setup method, to see if
it is being called.

···

--
Posted via http://www.ruby-forum.com/.