gpt4 book ai didi

ruby - 当我有多个带参数的方法时,如何使用页面对象导航路由?

转载 作者:数据小太阳 更新时间:2023-10-29 08:03:56 24 4
gpt4 key购买 nike

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

特点:

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

最佳答案

这是来自 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

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

关于ruby - 当我有多个带参数的方法时,如何使用页面对象导航路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27079179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com