【问题标题】:How can I use pageobject navigation routes when I have multiple methods with parameters?当我有多个带参数的方法时,如何使用 pageobject 导航路由?
【发布时间】:2014-11-22 15:40:53
【问题描述】:

在这里,我在一个类中有两个方法,每个方法都有一个参数,我想利用路由优势。如果我使用黄瓜,如何传递参数我的意思是,如果我这样使用,如何将参数从步骤定义传递到方法:

特点:

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 |

步骤定义:

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 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

路线:

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

【问题讨论】:

  • 或者任何人都可以建议我在使用带有路由的场景大纲时使用更好的方法。

标签: ruby selenium-webdriver cucumber watir-webdriver page-object-gem


【解决方案1】:

这是来自PageObject::PageFactory 的示例,其中 Cheezy 将参数传递给方法作为其路由定义的一部分:

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

当然,问题是在定义这些路由时您没有该参数。您需要动态加载它们。这样的东西可能有效,但我还没有测试过:

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

但是,如果您要解决所有这些麻烦,最好将块传递给 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

【讨论】:

    猜你喜欢
    • 2019-10-27
    • 1970-01-01
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 2019-11-15
    • 1970-01-01
    相关资源
    最近更新 更多