平等

2012-10-29 26 views
3

的Watir測試對黃瓜/測試的Watir工作來測試一個像器/循環工作。我的策略是通過css類抓取旋轉器中的活動圖像並將其轉儲到變量中。然後我點擊下一步按鈕,抓住活動圖像(現在應該是一個新的圖像)通過css類肩並轉存到第二個變量。然後,我應該可以說img_rot_1!= img_rot_2並讓測試返回true或false。這是我遇到麻煩的部分。平等

我是新來的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 and img_rot_1 == img_rot_2 both pass - so what I I missing?

回答

0

對於Then步驟就是失敗的,它需要一個失敗的斷言,不只是計算結果爲虛假的陳述。

假設你正在使用的RSpec的期望,你會想是這樣的:

img_rot_1.should_not eq(img_rot_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