如何在页面对象类中使用Rspec期望值。我需要断言元素。目前,我正在使用xpath,其他定位器来检查元素是否存在。我知道使用它是步骤定义。但我在课堂上需要它。
代码:
class AssertTest
include PageObject
span(:success, text: "Message added successfully")
def assert_element
success_element.when_present (or) success?
# I need to use Rspec expectations instead
# continue...
end
end在步骤定义中,我可以这样使用它:
@current_page.text.should include "message"发布于 2014-07-18 11:11:36
假设您已经需要“RSpec”,那么只需在类中包含RSpec::Matchers模块即可。
class AssertTest
include PageObject
include RSpec::Matchers
span(:success, text: "Message added successfully")
def assert_element()
# Example assertions for checking element is present
success_element.should be_visible
expect(success_element).to be_visible
end
end注意,有些人建议只在测试中进行断言(而不是在页面对象中)。
https://stackoverflow.com/questions/24816987
复制相似问题