jsoup Hamcrest Matchers

Hamcrest matchers to support the use of Jsoup in tests.

License

License

Categories

Categories

Net jsoup Business Logic Libraries
GroupId

GroupId

net.oneandone.jsoup
ArtifactId

ArtifactId

jsoup-hamcrest
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

jsoup Hamcrest Matchers
Hamcrest matchers to support the use of Jsoup in tests.
Project URL

Project URL

https://github.com/1and1/jsoup-hamcrest
Project Organization

Project Organization

1&1
Source Code Management

Source Code Management

https://github.com/1and1/jsoup-hamcrest/

Download jsoup-hamcrest

How to add to project

<!-- https://jarcasting.com/artifacts/net.oneandone.jsoup/jsoup-hamcrest/ -->
<dependency>
    <groupId>net.oneandone.jsoup</groupId>
    <artifactId>jsoup-hamcrest</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.oneandone.jsoup/jsoup-hamcrest/
implementation 'net.oneandone.jsoup:jsoup-hamcrest:1.0.0'
// https://jarcasting.com/artifacts/net.oneandone.jsoup/jsoup-hamcrest/
implementation ("net.oneandone.jsoup:jsoup-hamcrest:1.0.0")
'net.oneandone.jsoup:jsoup-hamcrest:jar:1.0.0'
<dependency org="net.oneandone.jsoup" name="jsoup-hamcrest" rev="1.0.0">
  <artifact name="jsoup-hamcrest" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.oneandone.jsoup', module='jsoup-hamcrest', version='1.0.0')
)
libraryDependencies += "net.oneandone.jsoup" % "jsoup-hamcrest" % "1.0.0"
[net.oneandone.jsoup/jsoup-hamcrest "1.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.jsoup : jsoup jar 1.12.1
org.hamcrest : hamcrest-core jar 2.2
org.hamcrest : hamcrest-library jar 2.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.
jsoup hamcrest
jsoup hamcrest
jsoup hamcrest

JSoup Hamcrest Matchers

jsoup-hamcrest brings the power of css matchers to your tests.

Maven

<dependencies>
    <dependency>
        <groupId>net.oneandone.jsoup</groupId>
        <artifactId>jsoup-hamcrest</artifactId>
        <version>1.0.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

You can check the latest version here.

Usage

jsoup-hamcrest uses a fluent api design to create your assertions, while still offering the comparability of Hamcrest matchers.

import static net.oneandone.jsoup.hamcrest.fluent.DocumentAssertions.anElement;  // (1)
import static net.oneandone.jsoup.hamcrest.fluent.JsoupAssertions.html;          // (1)

html(source)                                                  // (2)
    .expect(anElement("#exampleInputEmail")                   // (3)
        .hasAttribute("placeholder")                          // (4)
        .hasAttribute("placeholder", "Email")                 // (5)
        .hasAttribute("placeholder", equalTo("Email")));      // (6)
  1. static import of factory methods for better readability (optional)

  2. create an instance of JsoupAssertions using html factory method

  3. create an expectation, you can create multiple expectations for a document by chaining expect or its alias and. anElement creates a matcher for a single element with the given css query. (There is also eachElement and elements for performing assertions on each element or on the collection of found elements respectively)

  4. hasAttribute asserts the existence of the placeholder attribute on the element

  5. hasAttribute asserts that the value of the placeholder attribute is Email

  6. hasAttribute asserts that the value of the placeholder attribute is Email using a hamcrest matcher, you could also use containsString for example.

For more examples take a look at the AllMatcherHappyTest or FluentExampleTest to see usage examples.

net.oneandone.jsoup

1&1

Open Source by 1&1 Group.

Versions

Version
1.0.0