【问题标题】:Getting "Failed assertion, no message given." as error when running Ruby Selenium Test Cases得到“断言失败,没有给出消息。”运行 Ruby Selenium 测试用例时出现错误
【发布时间】:2012-02-01 17:25:45
【问题描述】:

我正在使用 selenium webdriver 编写测试,以下代码返回错误消息“断言失败,未给出消息。”:

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 标签和类。只是 selenium webdriver 找不到这个元素,并抛出这个不确定的错误。帮忙?

【问题讨论】:

    标签: ruby testing selenium 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")}
    

    【讨论】:

    • 但是当我在 Linux 中运行相同的代码时,一切正常。这是Windows的问题吗?我请我的一个朋友在他的 Windows 上尝试相同的代码并得到相同的错误。 Linux 也适合他。有什么建议吗?
    【解决方案2】:

    Webdriver 从网页返回 unicode 值。将常规字符串与 unicode 进行比较可能是代码中的断言失败的原因。

    另一个猜测是元素文本值中的尾随空格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      • 2011-01-25
      • 2017-11-11
      相关资源
      最近更新 更多