Kotest Jsoup Matchers

Explains Jsoup matchers.

This page lists the current matchers in the Kotest jsoup matcher extension library. To use this library, add kotest-assertions-jsoup to your build.

Element Description
element.shouldHaveChildWithTag(tag) Checks that the element has a child element with the given tag.
element.shouldHaveText(text) Checks that the element has the given text.
element.shouldHaveAttribute(name) Checks that the element has an attribute with the given name.
element.shouldHaveAttributeValue(name, value) Checks that the element has an attribute with the given value.
Elements Description
elements.shouldBePresent() Checks that the Elements object has any items.
elements.shouldBePresent(n) Checks that the Elements object has n items.
elements.shouldBePresent(n) Checks that the Elements object has n items.
HTML Description
element.shouldHaveId(id) Checks that the element has an ID attribute with the given value.
element.shouldHaveClass(class) Checks that the element has the specified class.
element.shouldHaveSrc(src) Checks that the element has a src attribute with the given value.
element.shouldHaveHref(href) Checks that the element has an href attribute with the given value.
element.shouldHaveElementWithId(id) Checks that the element has a child item with the given ID.
element.shouldHaveChildWithClass(id) Checks that the element has a child with the given class.

References