Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Watir 通过PageFactory传递参数_Watir_Page Object Gem - Fatal编程技术网

Watir 通过PageFactory传递参数

Watir 通过PageFactory传递参数,watir,page-object-gem,Watir,Page Object Gem,我正在使用页面对象gem与watir和RSpec一起测试我的web应用程序。 这是我的页面对象 require 'page-object' class UserEditPage include PageObject page_url "#{$context}/user/edit?id=#{@params[:id]}" text_field :user_id, name: 'userName' text_field :pw, name: 'password' text_f

我正在使用页面对象gem与watir和RSpec一起测试我的web应用程序。 这是我的页面对象

require 'page-object'

class UserEditPage
  include PageObject
  page_url "#{$context}/user/edit?id=#{@params[:id]}"

  text_field :user_id, name: 'userName'

  text_field :pw, name: 'password'
  text_field :pw_retype, name: 'password2'

  # snip uninteresting stuff

  button :submit, index: 0
end
我想通过
PageObject::PageFactory
page\u url
中参数化
:id
,如下所示:

visit UserEditPage, using_params: {id: 1000} do |page|
# operation on page
end
这意味着上述用法是可能的,但我不明白这到底是如何实现的

问题:如何将参数
id
从访问方法传递到
UserEditPage

运行代码会导致

       ***/user/edit_page.rb:8:in `<class:UserEditPage>': undefined method `[]' for nil:NilClass (NoMethodError)
        from ***/user/edit_page.rb:5:in `<top (required)>'
***/user/edit_page.rb:8:in`:nil:NilClass(NoMethodError)的未定义方法“[]”
从***/user/edit_page.rb:5:in`'
可能是因为在计算页面url时,
@params
为零。
使用参数{id:1000}将
更改为
id:1000
,但运气不佳。

页面url
需要:

page_url "#{$context}/user/edit?id=<%=params[:id]%>"

页面的url
需要:

page_url "#{$context}/user/edit?id=<%=params[:id]%>"

这样可以消除NoMethodError,但仍然无法传递参数<代码>访问方法转到
http://xxxx/user/edit?id=
,即没有参数替换。我添加了一个完整的工作示例,我认为它反映了您正在做的事情,并显示了替换的工作。如果您没有得到替换,我会在页面的url中再次检查(1),您使用的是
它工作正常。非常感谢。我的错是
。我认为这值得正式记录。这消除了NoMethodError,但仍然无法传递参数<代码>访问
方法转到
http://xxxx/user/edit?id=
,即没有参数替换。我添加了一个完整的工作示例,我认为它反映了您正在做的事情,并显示了替换的工作。如果您没有得到替换,我会在页面的url中再次检查(1),您使用的是
它工作正常。非常感谢。我的错是
。我认为这值得正式记录。