cfpb / macropolo

Other
1 stars 6 forks source link

Can I check for multiple classes in an assert? #5

Open KimberlyMunoz opened 9 years ago

KimberlyMunoz commented 9 years ago

So there's syntax for checking the class of selector. It's nifty and works like this:

                {
                    "selector": ".calendar-icon span",
                    "index": 0,
                    "value": "u-visually-hidden",
                    "assertion": "equal",
                    "attribute": "class"
                },

But if there's multiple classes, I can't figure out how to test. If I only do one like this, it'll fail.

               {
                   "selector": ".form-l_col",
                    "value": " form-l_col-1",
                    "assertion": "equal",
                    "attribute": "class"
                }

If I check for all the classes, it'll fail.

               {
                    "selector": ".form-l_col",
                    "value": "form-l_col form-l_col-1 form-l-inset",
                    "assertion": "equal",
                    "attribute": "class"
                }

Can we add some way to test for things with multiple classes?

willbarton commented 9 years ago

Apparently BeautifulSoup, which Macro Polo is using to parse the resulting HTML, treats multiple classes as a list.

>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup("<p class='bar feh omg'></p>")
>>> soup.select('p')
[<p class="bar feh omg"></p>]
>>> soup.select('p')[0].get('class')
['bar', 'feh', 'omg']

This means your specification will have to do that as well, I think.

{
    "selector": "p",
    "value": ["bar", "feh", "omg"],
    "assertion": "equal",
    "attribute": "class"
}

I'll try to find a way to make that a bit less awkward.