本文介绍了在定义页面对象时,是否可以使用siteprism变量定义新变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个黄瓜,ruby,capybara,siteprism项目,我们在一个siteprism页面对象中定义大多数英国变量。

I'm working on a cucumber, ruby, capybara, siteprism project and we're defining most UK variables in a siteprism page object.

有没有办法使用我创建的siteprism变量作为新变量定义的一部分?

Is there a way for me to use the siteprism variables that I create as part of the definition for new variables?

例如,如果我有一个siteprim页面,如下所示:

For example, if I've got a siteprim page that looks like:

sections :user_container, "#user_container" do
   sections :address_module, "#address" do
       element :house_number, "#house_number"
   end
end

我可以在同一个pageobject声明中定义新的变量,例如:

Can I somehow define new variables on the same pageobject declaration, something like:

element :postcode, :user_container[2].:address_module[1].text
OR
element :postcode, ":user_container[2].:address_module[1].text"
OR
some other syntax or workaround?

谢谢。

推荐答案

查看节的site_prisms代码 - - 可以看到所有它做的是在类上定义方法。它不会将传递给它的参数存储在以后可以访问的任何地方或任何用户可访问的变量中。因此,没有办法在其他元素/节调用中重用它们。你可以做的只是在类(页面对象)定义方法你要访问邮政编码,如

From a look at site_prisms code for sections - https://github.com/natritmeyer/site_prism/blob/master/lib/site_prism/element_container.rb#L33 - one can see that all it's doing is defining methods on the class. It doesn't store the arguments passed to it anywhere that can be accessed later or in any user accessible variables. So, no there's no way to reuse them in other element/section calls. What you can do is just define methods on the class (page object) where you want to access the postcode like

def postcode
  user_container[2].address_module[1].text
end

这篇关于在定义页面对象时,是否可以使用siteprism变量定义新变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:33