在黃瓜/ Watir-webdriver /頁面對象環境中,我需要驗證常見頁眉和頁腳鏈接的存在和功能。雖然這些都應該是相同的,並且工作,但我想將它們包括在所有相關頁面中。常見頁面元素 - 它們可以被繼承嗎?
我試圖跟上DRY編碼,並且希望最小化我需要確定在Web應用程序上共享的頁眉/頁腳元素的次數。
我以爲我可以通過在支持/文件夾出頭「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
試圖使用這兩種方法都沒有成功。
有沒有人成功地在一個文件/模塊/類中聲明通用鏈接(如頁眉/頁腳),然後從另一個類中使用它們?
任何方向將不勝感激。
賈斯汀 - 感謝洞察力。我得到了這個工作,其中一部分是由於我使用的'nav'聲明。我試圖抓住嵌套的元素,但必須實現在https://github.com/cheezy/page-object/wiki/Nested-Elements提供的指導 - 在這裏感謝您的幫助和以前的職位,你回答! – 2013-03-25 22:57:07