【发布时间】:2013-10-08 14:42:08
【问题描述】:
如果能帮助我对以下代码中的错误进行排序,我将不胜感激:
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
奇怪的是,脚本随后运行完成,并显示了 google 登录页面。
请注意,目前还没有断言 - 我一次只做一小步。
编辑后添加:
C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:971 中的初始化器
def initialize name # :nodoc:
@__name__ = name
@__io__ = nil
@passed = nil
end
【问题讨论】:
-
Test::Unit::TestCase 是否要求您在 TestGoogle 类中实现顶级方法? IOW,它是基类中的虚拟吗?
-
TestGoogle只是从Test::Unit::TestCase继承initialize。Test::Unit::TestCase初始化程序是否需要参数?尽管它看起来可以工作,但测试类中有一些东西不起作用,你可能只是暂时没有使用。 -
@mbratch:这是初始化程序的代码,对我来说几乎没有任何意义:
-
为什么要手动创建测试用例的实例并运行其方法(即为什么不使用实际的测试/单元运行器)?
-
请在您的帖子中包含
initialize,以便阅读其格式。在我看来,您有一个参数name到initialize,但是,您在没有参数的情况下调用TestGoogle.new。这将调用不带参数的initialize,因此会出现错误wrong number of arguments (0 for 1)。
标签: watir watir-webdriver testunit