Using ruby and cheezy page-object gem (along with cucumber).
I have a page_section
(section B) who's elements will vary based off the value of another page_section
(section A). I can access each page_section
fine but I'm trying to pass the value from section B to section A and I can't seem to make it work. I have a variable in section B (not sure of any better way to do it) that I initialize to the value of a span from section A. This doesn't work and gives a NoMethodError
. Can anyone help me with what I'm trying to do here? I know the title says Page Objects (and technically they are page objects) but I'm going to be using them as page_sections
of the same root page.
Section B code
class SectionB
include PageObject
coverage = on(SectionA).coverage_value
def element_method
element('element', id: coverage)
end
end
Section A code
class SectionA
include PageObject
def coverage_value
span_element(id: 'coverage-id')
end
end
The current approach will determine the coverage
when the class is compiled. I think you want to determine the value when the object is initialized.
I would initialize a SectionA instance within SectionB:
class SectionB
include PageObject
def coverage
SectionA.new(root.browser).coverage_value
end
def element_method
element('element', id: coverage)
end
end