Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

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

Open
KimberlyMunoz opened this issue Sep 3, 2015 · 1 comment
Open

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

KimberlyMunoz opened this issue Sep 3, 2015 · 1 comment

Comments

@KimberlyMunoz
Copy link

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
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants