Skip to content

ulfsauer0815/assertj-jsoup

Repository files navigation

AssertJ assertions for HTML

build Maven JitPack coveralls codecov

Provides assertions for HTML content including a Kotlin DSL. Uses jsoup for parsing.

Example

Kotlin DSL

assertThatSpec(document) {

    node("h1") { exists() }
    
    node(".example-code") { containsText("Kotlin") }
    
    node(".github-link") {
        hasText("Fork me on GitHub")
        attribute("href") {
            containsText("github")
            containsText("assertj-jsoup")
        }
        attribute("target") { hasText("_blank") }
        attribute("disabled") { notExists() }
    }
}

Java / Kotlin

assertThat(document)
    .elementExists("h1")
    
    .elementContainsText(".example-code", "Kotlin")

    .elementHasText(".github-link", "Fork me on GitHub")
    .elementAttributeContainsText(".github-link", "href", "github")
    .elementAttributeContainsText(".github-link", "href", "assertj-jsoup")
    .elementAttributeHasText(".github-link", "target", "_blank")
    .elementAttributeNotExists(".github-link", "disabled");

Build configuration

Kotlin

build.gradle.kts

repositories {
    mavenCentral()
}

testImplementation("io.github.ulfs:assertj-jsoup:0.1.4")

Gradle

build.gradle

repositories {
    mavenCentral()
}

testImplementation "io.github.ulfs:assertj-jsoup:0.1.4"

Development

see DEVELOPMENT.md