Ruby 如何在页面对象类中使用Rspec期望值
如何在页面对象类中使用Rspec期望值。我需要断言元素。目前我正在使用xpath和其他定位器来检查元素是否存在。我知道使用它是步骤定义。但我在课堂上需要它 代码: 在步骤定义中,我可以像这样使用它:Ruby 如何在页面对象类中使用Rspec期望值,ruby,rspec,cucumber,page-object-gem,rspec-expectations,Ruby,Rspec,Cucumber,Page Object Gem,Rspec Expectations,如何在页面对象类中使用Rspec期望值。我需要断言元素。目前我正在使用xpath和其他定位器来检查元素是否存在。我知道使用它是步骤定义。但我在课堂上需要它 代码: 在步骤定义中,我可以像这样使用它: @current_page.text.should include "message" 假设您已经需要“rspec”,只需要在类中包含rspec::Matchers模块 class AssertTest include PageObject include RSpec::Matchers
@current_page.text.should include "message"
假设您已经需要“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
请注意,有些人建议只在测试中执行断言(而不是在页面对象中)。假设您已经需要“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
请注意,有些人建议只在测试中执行断言(而不是在页面对象中)。肯定要支持Justin关于将断言放入页面类的警告!绝对要支持Justin关于将断言放入页面类的警告!