2015-08-24 33 views
0

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

World(PageObject::PageFactory) 

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

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

我知道我可以在没有PageFactory的情况下做到这一点,但是使用PageObject这种方式让我感觉就像在作弊一样容易。我想要使​​用这些模式。

visit(NewAccountPage) 
on(NewAccountPage).create_account 

也许还有另一种方式完全是?

回答

1

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

  1. 包括您要使用的visiton等方法在对象的PageObject::PageFactory。 (这是黄瓜的World方法正在做什么。)
  2. Watir::Browser对象定义一个@browser变量。

这里是在主使用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" 
相关问题