2009-12-31 26 views
4

我正在使用Cucumber,webrat和selenium來測試一個web應用程序。我使用''我應該看到'東西''來驗證更改。然而,在許多地方,只有被驗證的文本從隱藏變爲可見(這可能是由從其本身或其祖先中刪除'隱藏'類造成的)。在這種情況下,上面的測試實際上並未驗證更改。我試圖使用'response.should_not have_tag(「div#myId.hidden」)',這是行不通的。建議如何測試它?Cucumber + webrat + selenium,我如何忽略隱藏文字?

環境:黃瓜0.3.11,硒客戶端1.2.17,webrat 0.6.0

謝謝。

回答

5

的案件,因爲這些我用這兩個自定義的步驟:

Then /^the element matched by "([^\"]*)" should be visible$/ do |locator| 
    selenium.should be_visible(locator) 
end 

Then /^the element matched by "([^\"]*)" should not be visible$/ do |locator| 
    selenium.should_not be_visible(locator) 
end 

把那些進入一個Ruby step_definitions /目錄下的文件。

所以,你的情況,而不是然後我應該能看到「東西」使用然後,通過「東西」相匹配的元素應該是可見的

+0

應該定位器是一個CSS選擇器或頁面上看到的一些文本? – 2009-12-31 18:42:23

+0

selenium.should be_visible 「分區#身份識別碼」 產生這個錯誤: 元DIV#身份識別碼未找到(硒:: CommandError) 我敢肯定它是一個有效的CSS選擇器。什麼可能出錯? – 2009-12-31 18:55:01

+0

使用「css = div#myId」(並在此閱讀更多內容:http://seleniumhq.org/docs/04_selenese_commands.html#locating-by-css)。 – 2009-12-31 18:57:05

3

當使用have_selector(「div#myId.hidden」)代替它時它工作嗎?

+0

這很有效。非常感謝。 – 2009-12-31 18:41:15

+0

不客氣,新年快樂:-) – schmitzelburger 2010-01-01 02:33:28

1

接受的解決方案不符合以下環境中工作:(0.10) 導軌(3.0.0),webrat(0.7.3)硒的客戶端(1.2.18),黃瓜

的解決方案,作品,與現在的答案中提供的示例是現在:

Then /^the element matched by "([^\"]*)" should be visible$/ do |locator| 
    selenium.is_visible(locator).should be_true 
end 

Then /^the element matched by "([^\"]*)" should not be visible$/ do |locator| 
    selenium.is_visible(locator).should_not be_true 
end 
+1

「selenium」在哪裏設置?我得到「未定義的方法'is_visible'爲零:NilClass」 – RyanJM 2012-04-30 21:46:46