rubyseleniumcapybarasite-prism

Check if section in Site Prism has class of specific type


Using Capybara in ruby and creating page objects with Site Prism. Http element looks like this:

<section class='service-widget'  id='service_id>
   <div class='title'> ... </div>
   <div class='content> ... </div>
</section>

I have created class for this section:

class ServicesSection < SitePrism::Section
end

and then added section to the page object:

class ServicesPage < SitePrism::Page
    sections :services, ServicesSection, 'section[id^="service_"]'
end

This element can be collapsed and only thing that indicates state of it(if it is collapsed or not) is it's class name which is changed from

<section class='service-widget'  id='service_id>

to

<section class='service-widget is-closed'  id='service_id>

How to find out that this element is collapsed(closed) or not?


Solution

  • Your self-answer of root_element[:class].include? 'is-closed' will probably work just fine for your case, but isn't robust since it would also match an element with a class of is-closed-tomorrow. A more robust solution would be the following:

    root_element.matches_css?('.is-closed', wait: false)