【问题标题】:Watir testing for equalityWatir 平等测试
【发布时间】:2012-10-29 22:13:49
【问题描述】:

进行 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 都通过了 - 那么我错过了什么?

【问题讨论】:

    标签: ruby cucumber watir


    【解决方案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
    

    【讨论】:

      【解决方案2】:

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

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

      img_rot_1.should_not eq(img_rot_2)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-04
        • 2015-07-31
        相关资源
        最近更新 更多