Open yatsan opened 11 years ago
What would you expect the behavior to be in this case? Would the Hash be passed to each page?
I thought about unique parameter names..like option_name in case above, so only those parameters will be passed to page method.
Here is how I implemented that in my project. Pretty tangled but working.
# Route example
PageObject::PageFactory.routes = {
default: [[HomePage, :home]],
account_details_route: [[Page, :accounts_tab],
[AccountsPage, :search_for, :account_name],
[AccountsSearchResultsPage, :open_account_page, :account_name],
[AccountPage, :account_details]]
}
module PageNavigation
module Routes
alias_method :original_routes=, :routes=
def routes=(routes)
@initial_routes ||= routes.dup
original_routes=(routes)
end
def reset_routes
@routes = @initial_routes.dup
end
end
end
module PageNavigation
alias_method :original_navigate_to, :navigate_to
def navigate_to(page_cls, params = {:using => :default}, &block)
route = params.delete(:using)
inject_params_into_route(route, params) unless params.empty?
original_navigate_to(page_cls, {using: route}, &block)
end
def inject_params_into_route(route, params)
PageObject::PageFactory.reset_routes
params.each do |injected_param_name, injected_param_value|
result = PageObject::PageFactory.routes[route].map do |step|
step.map do |step_attribute|
step_attribute == injected_param_name ? injected_param_value : step_attribute
end
end
PageObject::PageFactory.routes[route] = result
end
end
end
It should be useful to have opportunity to pass parameters to navigate_all like:
navigate_all(:using => :select_route, {:option_name =>'option1', :address => 'some address'})
env.rb PageObject::PageFactory.routes = { ... :select_route=> [[HomePage, :goto], [HomePage, :select, :option_name ], [OrderPage, :add_address, :address], [OrderPage, :submit_order]] }