我一直在努力解决这个问题。我查看了太多帖子,甚至尝试了另一个类似的gem(Page-Object),结果相同。
我似乎错过了关于如何实例化对象的观点。
如果有人能够启发我,我将不胜感激。
最佳,
JFF
这是我按照https://github.com/KualiCo/TestFactory:
的说明构建的脚本class MainPage < PageFactory
class << self
def basic_element
action(:my_request_is) { |b| b.text_field(name: 'q').set }
action(:search) { |b| b.button(name: 'btnK').click }
end
end
end
require 'watir'
require 'test-factory'
require './lib/Base_Page'
include Foundry
RSpec.configure do |config|
browser = Watir::Browser.new :firefox
config.before(:all) { @b = browser }
config.before(:each) { @b.goto("http://google.com") }
config.after(:suite) { browser.close unless browser.nil? }
end
describe 'Search_Page' do
it 'allows me to search for a DataObject' do
on_page MyPage do |page|
page.my_request_is "Hello World"
end
end
end
> Search_Page allows me to search for a DataObject (FAILED - 1)
>
> Failures:
>
> 1) Search_Page allows me to search for a DataObject
> > Failure/Error:
> > > on_page MyPage do |page|
> > > > page.my_request_is "Hello World"
> > > end
>
> NameError:
> uninitialized constant MyPage
> # ./spec/search_spec.rb:20:in `block (2 levels) in <top (required)>'
>
> Finished in 3.37 seconds (files took 7.25 seconds to load) 1 example,
> 1 failure
>
> Failed examples:
>
> rspec ./spec/search_spec.rb:18 # Search_Page allows me to search for a
> DataObject
答案 0 :(得分:0)
有几个问题:
on_page
假设浏览器存储在@browser
(不是@b
)。class << self
用于类似基类的页面类,以定义可包含在特定页面类中的节。由于此时您没有使用基类,因此可以将其删除。尝试以下方法:
class MainPage < PageFactory
action(:my_request_is) { |v, b| b.text_field(name: 'q').set(v) }
action(:search) { |b| b.button(name: 'btnK').click }
end
RSpec.configure do |config|
browser = Watir::Browser.new :chrome
config.before(:each) { @browser = browser }
config.before(:each) { @browser.goto("http://google.com") }
config.after(:suite) { browser.close unless browser.nil? }
end
describe 'Search_Page' do
it 'allows me to search for a DataObject' do
on_page MainPage do |page|
page.my_request_is "Hello World"
end
end
end