Module: LitePage::PageInitializers

Defined in:
lib/lite_page/page_initializers.rb

Instance Method Summary collapse

Instance Method Details

#on(page_class, browser = @browser) {|page| ... } ⇒ Object

Initializes and returns an instance of the given page class. Yields the page instance to a block if given.

Parameters:

  • page_class (Class)

    the page class

  • browser (Object) (defaults to: @browser)

    the browser instance

Yields:

  • (page)

    yields page instance to a block



27
28
29
30
31
# File 'lib/lite_page/page_initializers.rb', line 27

def on(page_class, browser = @browser)
  page = page_class.new(browser)
  yield page if block_given?
  page
end

#visit(page_class, query_params = {}, browser = @browser) {|page| ... } ⇒ Object

Initializes an instance of the given page class, drives the given browser instance to the page's url with any given query parameters appended, yields the page instance to a block if given, and returns the page instance.

Parameters:

  • page_class (Class)

    the page class

  • query_params (Hash, Array) (defaults to: {})

    the query parameters to append to the page url to viist

  • browser (Object) (defaults to: @browser)

    the browser instance

Yields:

  • (page)

    yields page instance to a block



11
12
13
14
15
16
17
18
19
# File 'lib/lite_page/page_initializers.rb', line 11

def visit(page_class, query_params = {}, browser = @browser)
  page = page_class.new(browser)

  url = query_params.empty? ? page.page_url : page.page_url(query_params)
  browser.goto(url)

  yield page if block_given?
  page
end