Giter VIP home page Giter VIP logo

cucumber-dressing's Introduction

Actions Status release version Apache2 license

Cucumber Dressing ๐Ÿฅ’โœจ

Simple Java helper library to use in combination with data tables in cucumber stepdefs.

Install library with:

Install with Maven

<dependency>
    <groupId>com.vijane.cucumber</groupId>
    <artifactId>cucumber-dressing</artifactId>
    <version>1.0.0</version>
</dependency>

Install with Gradle

implementation 'com.vijane.cucumber:cucumber-dressing:1.0.0'

Install with Gradle Kotlin DSL

implementation("com.vijane.cucumber:cucumber-dressing:1.0.0")

Table of contents

  1. Introduction
  2. Usage

Introduction

Cucumber Dressing is a simple java helper library to use in combination with data tables in cucumber stepdefs.

Usage

Cucumber Dressing will map your data table from your feature file easily to Java objects. See below for an example use case:

Feature file

Feature: Some basic grocery validations

  Scenario:
    Given I have a budget of 100 euro's
    And I have the following grocery list
      | name    | amount | price | expirationDate            |
      | apple   | 5      | 0.4   | (today+15)T00:00:00.000Z  |
      | onion   | 10     | 0.25  | (today+20)T00:00:00.000Z  |
      | potato  | 10     | 0.20  | (today+22)T00:00:00.000Z  |
      | ketchup | 1      | 2.49  | (today+90)T00:00:00.000Z  |
      | rice    | 2      | 4.95  | (today+180)T00:00:00.000Z |
    When I go out and buy everything
    Then I expect to have some money left over
    And I validate the products will not expire at least for the next 14 days

Mapping of data table

import java.math.BigDecimal;
import java.time.ZonedDateTime;

import com.vijane.cucumber.dressing.DataElement;
import com.vijane.cucumber.dressing.DataElementTransformer;

public class GroceryDataTableMapper
    implements DataElement
{

    @DataElementTransformer
    private String name;

    @DataElementTransformer
    private BigDecimal amount;

    @DataElementTransformer( defaultValue = "0.0" )
    private BigDecimal price;

    @DataElementTransformer( value = "expirationDate", converter = DataElement.class, method = "getZonedDateTimeFromString(java.lang.String)", mandatory = false )
    private ZonedDateTime expirationDate;

    public static class Builder
    {
        public Product from( GroceryDataTableMapper mapper )
        {
            return new Product( mapper.name, mapper.amount, mapper.price, mapper.expirationDate );
        }
    }

}

Usage within your stepdefs

import com.vijane.cucumber.dressing.DataCollection;
import com.vijane.cucumber.dressing.model.GroceryDataTableMapper;
import com.vijane.cucumber.dressing.model.Product;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.And;

import java.util.List;
import java.util.stream.Collectors;

public class GroceryStepDefs {

    @And("I have the following grocery list")
    public void iHaveTheFollowingGroceryList(DataTable dataTable) {
        List<Product> products = DataCollection.create(dataTable, GroceryDataTableMapper.class).stream()
                .map(row -> new GroceryDataTableMapper.Builder().from(row))
                .collect(Collectors.toList());
    }
    
}

cucumber-dressing's People

Contributors

jeaninev avatar idhub-bot avatar hakky54 avatar

Stargazers

LiTong avatar  avatar

Watchers

 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.