Question

I would be grateful for help in sorting the error in the following code:

require 'rubygems'
require 'watir'
require 'watir-webdriver'
require 'test/unit'

class TestGoogle < Test::Unit::TestCase    
  def setup
    @browser = Watir::Browser.new :firefox
  end

  def testSignInLink
    @browser.goto "http://google.com/"
    po = PageObjects.new(@browser)
    po.clickLinkSignIn
  end
end

class PageObjects
  def initialize( browser )
    @browser = browser
  end

  def clickLinkSignIn()
    @browser.link(:id, "gb_70").click
  end
end

tg = TestGoogle.new
tg.setup
tg.testSignInLink

The error is:

Uncaught exception: wrong number of arguments (0 for 1)
C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:971:in `initialize'
C:/RubymineProjects/ditto/Google_01_TU_02.rb:28:in `new'
C:/RubymineProjects/ditto/Google_01_TU_02.rb:28:in `<top (required)>'

Line 28 is:

tg = TestGoogle.new

Strangely enough, the script then runs to completion with the google login page being presented.

Note that there are no asserts yet - I'm doing this one small step at a time.

Added after edit:

The initializer in C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:971

  def initialize name # :nodoc:
    @__name__ = name
    @__io__ = nil
    @passed = nil
  end
Était-ce utile?

La solution

I think this whole question was unfair to all the good commenters.

Reason: As an experiment, I commented out the last 3 lines of the code:

tg = TestGoogle.new
tg.setup
tg.testSignInLink

The test ran perfectly.

I was previously assuming that I needed some way to "kick start" the methods in the TestGoogle class. Similar to a "Main" program that calls all the methods in turn.

Maybe that's what @justinko was referring to? So, the TestGoogle class is a test runner?

I think I need to apologize to the commenters.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top