spe*_*tor 1 ruby rspec cucumber page-object-gem rspec-expectations
如何在页面对象类中使用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
Run Code Online (Sandbox Code Playgroud)
在步骤定义中,我可以像以下一样使用它:
@current_page.text.should include "message"
Run Code Online (Sandbox Code Playgroud)
假设您已经需要'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
Run Code Online (Sandbox Code Playgroud)
请注意,有些人会建议只在测试中进行断言(而不是在页面对象中).