在 cucumber/Watir-webdriver/page-object 环境中,我需要验证常见页眉和页脚链接的存在和功能。虽然这些都应该是相同的,并且有效,但我想将它们包含在所有相关页面上。
我正在尝试跟上 DRY 编码,并希望最大限度地减少识别 Web 应用程序上共享的页眉/页脚元素所需的次数。
我想我可以通过在 support/ 文件夹中包含一些“common_links.rb”来做到这一点:
module CommonLinks
include PageObject
# Header links
link(:log_out_header_link, :text => "Log Out")
link(:logo, :id => "logo")
#Logged in nav links
div(:nav, :id => "globalnav_wrapper")
nav.link(:nav_activities, :href => "/activities/")
# Footer Links
link(:contact_us_footer, :text => "CONTACT US")
# Social Media Links
link(:social_twitter, :id => "soc_twitter")
link(:social_facebook, :id => "soc_fb")
link(:social_pinterest, :id => "soc_pin")
link(:social_google_plus, :id => "soc_gplus")
link(:social_youtube, :id => "soc_yt")
end
我正在尝试将上述内容包含在support/pages/activities_page.rb
. 当我尝试加载调用它的黄瓜功能时,我收到以下错误:
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/page-object-0.8.6.1/lib/page-object/accessors.rb:1110:in `block (2 levels) in <module:Accessors>'
/Users/user_name/svn/watir/cukes/client/features/support/common_links.rb:12:in `<module:CommonLinks>'
/Users/user_name/svn/watir/cukes/client/features/support/common_links.rb:1:in `<top (required)>'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `each'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:175:in `load_step_definitions'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/runtime.rb:40:in `run!'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/lib/cucumber/cli/main.rb:20:in `execute'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.2.1/bin/cucumber:14:in `<top (required)>'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `load'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `<main>'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
/Users/user_name/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
我还尝试创建一个“CommonPage”类,并从中继承,但我得到了一个未初始化的常量错误。CommonPage 类与模块相同。
class CommonPage
include PageObject
#Header links
link(:log_out_header_link, :text => "Log Out")
link(:logo, :id => "logo")
#Logged in nav links
div(:nav, :id => "globalnav_wrapper")
nav.link(:nav_activities, :href => "/activities/")
# Footer Links
link(:contact_us_footer, :text => "CONTACT US")
# Social Media Links
link(:social_twitter, :id => "soc_twitter")
link(:social_facebook, :id => "soc_fb")
link(:social_pinterest, :id => "soc_pin")
link(:social_google_plus, :id => "soc_gplus")
link(:social_youtube, :id => "soc_yt")
end
尝试使用这些方法中的任何一种都没有成功。
有没有人成功地在一个文件/模块/类中声明公共链接(如页眉/页脚),然后从另一个类中使用它们?
任何方向将不胜感激。