为什么以下代码中存在错误?

时间:2013-10-08 14:42:09

标签: watir watir-webdriver testunit

我将非常感谢您在以下代码中对错误进行排序:

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

错误是:

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)>'

第28行是:

tg = TestGoogle.new

奇怪的是,该脚本随后将显示谷歌登录页面。

请注意,还没有断言 - 我一次只做一小步。

编辑后添加:

C中的初始化程序:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:971

  def initialize name # :nodoc:
    @__name__ = name
    @__io__ = nil
    @passed = nil
  end

1 个答案:

答案 0 :(得分:0)

我认为这整个问题对所有优秀的评论者都不公平。

原因:作为一项实验,我注释掉了代码的最后3行:

tg = TestGoogle.new
tg.setup
tg.testSignInLink

测试完美无缺。

我以前认为我需要一些方法来“启动”TestGoogle类中的方法。类似于依次调用所有方法的“主”程序。

也许这就是@justinko指的是什么?那么,TestGoogle类是一个测试运行者?

我想我需要向评论者道歉。

相关问题