3

进行 Cucumber/Watir 测试以测试图像旋转器/循环是否正常工作。我的策略是通过 css 类抓取旋转器中的活动图像并将其转储到变量中。然后我单击下一个按钮并通过 css 类在旋转器中抓取活动图像(现在应该是新图像)并将其转储到第二个变量中。然后我应该可以说 img_rot_1 != img_rot_2 并让测试返回真或假。这是我遇到麻烦的部分。

我是 Ruby 新手,所以我可能会遗漏一些简单的东西。这是测试。

require 'step_definition/setup'

test_setup = Wsetup.new 'http://loginurl', 'uname', 'pass' # browser object created here as # test_setup.b
img_rot_1 = String.new
img_rot_2 = String.new 

When /^I click the next image button$/ do
  test_setup.do_login
  test_setup.b.goto('http://psu.dev1.fayze2.com/node/56')
  img_rot_1  = test_setup.b.li(:class => 'flex-active-slide').img.src
  test_setup.b.link(:class => 'flex-next').click
end

Then /^the rotator should move to the next image$/ do
  img_rot_2  = test_setup.b.li(:class => 'flex-active-slide').img.src
  img_rot_1 != img_rot_2
end

img_rot_1 != img_rot_2 和 img_rot_1 == img_rot_2 都通过了 - 那么我错过了什么?

4

2 回答 2

1

我认为如果要访问在另一步骤中创建的变量,则必须使用实例变量。

就像是:

When /^I click the next image button$/ do
  # more code here
  @img_rot_1  = test_setup.b.li(:class => 'flex-active-slide').img.src
end

Then /^the rotator should move to the next image$/ do
  img_rot_2  = test_setup.b.li(:class => 'flex-active-slide').img.src
  @img_rot_1.should_not == img_rot_2
end
于 2012-10-29T14:13:49.917 回答
0

对于Then失败的步骤,它需要一个失败的断言,而不仅仅是一个评估为假的语句。

假设您使用的是 RSpec 期望值,您可能需要如下内容:

img_rot_1.should_not eq(img_rot_2)
于 2012-10-29T13:30:51.960 回答