How can I use page navigation routes when I have multiple methods with parameters?

Here I have two methods in a class with one parameter each and I want to take advantage of routes. How do I pass parameters if I am using a cucumber? I mean, how can I pass parameters from step definitions to a method if I use like this:

function:

Feature: Github Test Case

Background:
  Given I am on githubpage

Scenario Outline: I should see one of the repositories
  When I click on "<user>" and select "<repo>" link
  Then I should see "Information Technology Association website repo"

Examples:
  | user   | repo        |
  | sample | sample_repo |

      

step def:

Given(/^I am on githubpage$/) do
 visit(LoginPage).do_login
end

Then(/^I should see "([^"]*)"$/) do |message|
  @current_page.text.should include message
end


When(/^I click on "([^"]*)" and select "([^"]*)" link$/) do |user, repo|
 # currently using like this
 navigate_to(GithubPage).click_on(user)
 navigate_to(GithubPage).select_repo(repo)

 # but i need like this
 navigate_to(GithubPage).select_repo

 # or
 navigate_all
end

      

Class:

  class GithubPage
  include PageObject

  link(:repo, text: /Repositories/)

  def click_on(user)
    span_element(text: "#{user}", index: 1).click
    repo_element.click
  end

  def select_repo(repo)
    link_element(xpath: "//a[contains(text(),'#{repo}')]").when_present.click
  end
end

      

routes:

PageObject::PageFactory.routes = {
    :default => [[GithubPage, :click_on], [GithubPage, :select_repo]]
}

      

+3


source to share


1 answer


Here's an example from PageObject :: PageFactory where Cheezy passes an argument to a method as part of defining its routes:

PageObject::PageFactory.routes = {
  :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]],
  :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]]
}

      

The problem, of course, is that you don't have this argument at the time that these routes are defined. You need to load them dynamically. Something like this might work, but I haven't tested it:



When /^I click on "([^"]*)" and select "([^"]*)" link$/ do |user, repo|
  PageObject::PageFactory.routes[:default].map do |route|
    route << user if route[1] == :click_on
    route << repo if route[1] == :select_repo 
  end
  navigate_all
end

      

But if you go for all these problems, you better pass the block to PageObject :: PageFactory # on:

When /^I click on "([^"]*)" and select "([^"]*)" link$/ do |user, repo|
  on GithubPage do |page|
    page.click_on user
    page.select_repo repo
  end
end

      

+2


source







All Articles