【问题标题】:how can i use Rspec Expectations in page object classes我如何在页面对象类中使用 Rspec 期望
【发布时间】:2014-07-18 03:56:39
【问题描述】:

如何在页面对象类中使用 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"

【问题讨论】:

    标签: ruby rspec cucumber page-object-gem rspec-expectations


    【解决方案1】:

    假设你已经需要 '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
    

    请注意,有些人会建议只在测试中进行断言(而不是在页面对象中)。

    【讨论】:

    • 绝对要赞同贾斯汀关于将断言放入页面类的警告!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多