在定义页面对象时,是否可以使用siteprism变量定义新变量?

编程入门 行业动态 更新时间:2024-10-24 16:22:25
本文介绍了在定义页面对象时,是否可以使用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代码 - github/natritmeyer/site_prism/blob/master/lib/site_prism/element_container.rb#L33 - 可以看到所有它做的是在类上定义方法。它不会将传递给它的参数存储在以后可以访问的任何地方或任何用户可访问的变量中。因此,没有办法在其他元素/节调用中重用它们。你可以做的只是在类(页面对象)定义方法你要访问邮政编码,如

From a look at site_prisms code for sections - github/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变量定义新变量?

本文发布于:2023-11-16 22:01:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   定义   可以使用   对象   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!