I am testing UI flow with Capybara and SitePrism stack. Unfortunately, my UI flow is not fully deterministic and sometimes a warning message pops up in the flow. Therefore I need to have a conditional flow in the test.
To wait for a single element, SitePrism provides the
@page.wait_for_<element name>
In my case there are two elements that can appear, :button_submit
or :warning_popup
. What I need to achieve is something like:
element_name = @page.wait_for_any_of(:button_submit, :warning_popup)
Is there some more elegant way other than running a loop like this?
element_name = nil
while (element_name.nil?) do
element_name = :button_submit if app.page.has_button_submit?
element_name = :warning_popup if app.page.has_warning_popup?
sleep 0.1
end
I know this loop can end up in infinite loop, I'll keep it here simplified for ilustration.
I don't believe site-prism provides any clean way for waiting for one of multiple elements, however a workaround would be to add an
element
to the page that would find either of the elements by using the CSS commaand then you could do