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

1

0

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.

Annihilation answered 14/2, 2017 at 21:29 Comment(0)
M
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
Metheglin answered 14/2, 2017 at 22:11 Comment(1)
Thanks for the explanation as always Thomas!, and for the workaround. Good idea :)Annihilation

© 2022 - 2024 — McMap. All rights reserved.