2012-01-03 86 views
0

我使用webdriver的硒寫測試,下面的代碼返回錯誤消息「無法斷言,沒有確定的消息。」:獲取「失敗的斷言,沒有給出消息。」作爲錯誤運行Ruby的硒測試用例時

product_name_error_message = @driver.find_element(:tag_name => "span", :class => "error").text 
assert product_name_error_message == "Product Name must be greater than 3 and less than 255 characters!" 

對不起,我一個Ruby的新手,我無法找到任何解決方案在網絡上的這個錯誤消息。我使用瀏覽器進行了檢查,該文本確實出現在頁面上,並具有適當的span標籤和類。只是硒webdriver找不到這個元素,並拋出這個不確定的錯誤。幫幫我?

回答

1

嘗試顯示運行第一行代碼後返回的值。

所以

product_name_error_message = @driver.find_element(:tag_name => "span", :class => "error").text 
puts product_name_error_message 
assert product_name_error_message == "Product Name must be greater than 3 and less than 255 characters!" 

我估計變量不反正認爲值。

而且你能俱樂部都在一條線 -

verify { assert(@driver.find_element(:tag_name => "span", :class => "error").text.include?(Product Name must be greater than 3 and less than 255 characters!"),"The text is present")} 
+0

但是,當我在Linux中運行相同的代碼,它一切正常。這是Windows的問題嗎?我問了我的一個朋友在他的Windows上嘗試了相同的代碼,並得到了同樣的錯誤。 Linux也適合他。有什麼建議麼? – 2012-01-07 18:26:39

1

的webdriver從網頁返回Unicode值。將常規字符串與unicode進行比較可能會導致代碼中的斷言失敗。

另一種猜測是在元素的文本值中尾隨空格。

相關問題