Is it possible to use siteprism variables to define new variables when defining the page object?

余生长醉 提交于 2019-12-25 06:53:44

问题


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

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

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

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?

Thank you.


回答1:


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


来源:https://stackoverflow.com/questions/42236583/is-it-possible-to-use-siteprism-variables-to-define-new-variables-when-defining

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!