capybara - With site_prism I dont know how the best practice if I want to use a variable called @current_page -



capybara - With site_prism I dont know how the best practice if I want to use a variable called @current_page -

you see, in code need set global variable set current_page (during 1 step) , reuse (in other step)

then /^i open "(.*?)" form$/ |form_type| form_page = "#{form_type}_page" @current_page = @home_page.send(form_page.to_sym) # here current page not same page have open_form method @current_page.open_the_form end /^i should ....$/ # here current_page reuse info previous step @current_page.do_something # sometimes, dont know set variable "current_page" end

but have maintenance issue coworkers, because, sometimes, when read code dont understand page @current_page ?

what best practice in case.

how utilize "current_page" variable without maintenance issue or ambiguity ?

with team, i've established rule our global page variable should refer right model @ times. instead of setting model directly, utilize few helpers.

we established convention page definition , steps go on same file. illustration some_page.rb

class somepage < siteprism::page set_url '/lol' set_url_matcher /#{@target}\/lol/ element :button, 'button' element :some_image, 'img' end given /^i have reached somepage$/ load_page somepage end when /^i click button on page$/ @page.button.click end /^i should on page$/ ensure_page somepage end /^some page should have image$/ @page.should have_some_image end

this might seem odd, , go against kinds of best practices - it's working great team. step definitions coupled respective page, know @page refers within definition, , it's lot easier , see elements mapped (or add together more mappings.) quick image of steps have written specific page, leads less duplicate step definitions.

on rare case 1 step definition used multiple pages, have separate helpers file go.

we have few helpers utilize setting , using global @page variable. using these, convention never @page = somepage.new or @page.should be_displayed

set_page used setting global variable instance of provided page. makes sure expected page displayed, , calls page#set_up. of our pages inherit masterpage class, has empty set_up method. can define set_up on page add together sort of initialization code when specific pages load.

def set_page page_model @page = page_model.new # ensure expected page displayed ensure_page page_model # phone call set_up method on page @page.set_up end

ensure_page used whenever want sure we're on right page. it's used both ensuring global variable refers right page, , page displayed. used in place of traditional pagemodel.new.should be_displayed

def ensure_page page_model unless @page.is_a? page_model raise pagemodelincorrect.new "@page #{@page.class} when #{page_model} expected.\ncurrent url: #{current_url}" end @page.should be_displayed end

load_page used instead of traditional pagemodel.new.load args. automatically loads page provided arguments, sets global variable method above, ensures page displayed.

def load_page(page_model, *args) page = page_model.new page.load(*args) set_page page_model end

capybara site-prism

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -