2016-01-30 25 views
0

在Rails應用程序,我有以下的CSS是返回true。可見?當它應該是假的

#step2 { display:none } 

我對這個條件的測試是在這裏

Then /^I should not see "([^\"]*)" because it is hidden$/ do |id| 
    s=page.find(id) 
    expect(s.visible?).to be false 
end 

當我手動,在彈出的頁面部分不可見。

的錯誤是

expected true 
     got false 
    (RSpec::Expectations::ExpectationNotMetError) 
    ./features/step_definitions/navagation_steps.rb:85:in `/^I should not see "([^\"]*)" because it is hidden$/' 
    features/profile.feature:10:in `And I should not see "#step2" because it is hidden' 

的page.find調用似乎正常工作。如果我打印我得到的物體

#<Capybara::Node::Element:0x007fd42ea30818> 

我試過各種不同的咒語都無濟於事。這似乎是最直接的。有沒有人在這裏看到這個問題?它讓我難住。

+0

嘗試'期待(s.visible?)。到be_falsey' .. –

+0

你跟水豚這些測試使用的是什麼驅動? –

+0

告訴你我是一個新手。我不知道司機是什麼。你如何確定? –

回答

0

期待(s.visible?)。not_to進行EQ(真)

這似乎是工作。

+0

你試過我的嗎?我所說的會起作用,因爲你的期望是錯誤的。 –

+0

是的,我試過了,它不適合我。不知道爲什麼。 –

0

使用的RSpec提供的動態謂詞匹配器將讀取更好,提供更好的錯誤消息

expect(s).not_to be_visible 

注意 - 如果您使用的是與水豚它不會處理最「外部默認架試車手「CSS所以它不能夠確定的知名度,除非顯示:無在元素的樣式屬性

0

您可以使用以下提到的方法,如果您要驗證的元素不是頁面上可見

Then /^I should not see "([^\"]*)" because it is hidden$/ do |id| 
    expect(page).to have_selector(<SELECTOR>,:visible => false) 
end 

或者,你也可以做同樣喜歡

Then /^I should not see "([^\"]*)" because it is hidden$/ do |id| 
    page.find(<SELECTOR>, :visible => false) 
end 

注:<SELECTOR>是一個元素的CSS選擇器。

希望這有助於:)

相關問題