我可以在没有黄瓜的情况下使用PageObject :: PageFactory吗?

时间:2015-08-24 08:06:35

标签: watir-webdriver page-object-gem

我想知道是否可以在没有黄瓜的情况下使用PageObject :: PageFactory。我用

试了一下
World(PageObject::PageFactory)

但没有没有黄瓜的世界。我无法找到另一种方式的例子。

为什么我会做一些疯狂的事情?我想创建一个可以由测试人员下载的gem,用于我们测试的产品。我喜欢cukes,但我也喜欢它用于探索性测试。我在其他终端上做到了这一点。

我知道我可以在没有PageFactory的情况下做到这一点,但它很容易使用PageObject,就像我作弊一样。我想使用这些模式。

visit(NewAccountPage)
on(NewAccountPage).create_account

也许完全有另一种方式?

1 个答案:

答案 0 :(得分:3)

是的,你可以。您需要做两件事:

  1. 在要使用PageObject::PageFactoryvisit等方法的对象中包含on。 (这就是Cucumber World方法正在做的事情。)
  2. @browser对象定义Watir::Browser变量。
  3. 以下是在main中使用PageFactory的示例:

    require 'watir-webdriver'
    require 'page-object'
    
    # A page object
    class GooglePage
      include PageObject
    
      page_url 'http://www.google.com'
    end
    
    # Including the page factory methods in the main
    include PageObject::PageFactory
    
    # Assign a browser to @browser
    @browser = Watir::Browser.new :chrome
    
    # Using the page factory
    visit(GooglePage)
    
    p on(GooglePage).current_url
    #=> "https://www.google.ca/?gfe_rd=cr&ei=UxfbVdnCAaeD8QeM96CACg&gws_rd=ssl"