Coder Social home page Coder Social logo

1and1 / jsoup-hamcrest Goto Github PK

View Code? Open in Web Editor NEW
4.0 21.0 0.0 26 KB

JSoup Hamcrest Matchers brings the power of css matchers to your tests.

License: Apache License 2.0

Java 93.63% HTML 6.37%
testing css-selector junit5 junit4 jsoup unit-testing acceptance-testing integration-testing hamcrest-matchers spock-framework

jsoup-hamcrest's Introduction

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.

jsoup-hamcrest's People

Contributors

leonard84 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.