Skip to content

Instantly share code, notes, and snippets.

View bcarun's full-sized avatar

Arun B Chandrasekaran bcarun

View GitHub Profile
@bcarun
bcarun / cucumber-in-springboot_cucumber-report-runner.java
Created June 17, 2019 02:17
Class to generate html report from cucumber runner's json report output
package com.arun.cucumber.hello.bdd;
import cucumber.api.junit.Cucumber;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;
package com.arun.cucumber.hello.bdd;
import static java.util.Locale.ENGLISH;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import cucumber.api.TypeRegistryConfigurer;
import io.cucumber.cucumberexpressions.ParameterByTypeTransformer;
package com.arun.cucumber.hello.bdd;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
/**
* To run cucumber test.
*/
@RunWith(Cucumber.class)
@bcarun
bcarun / cucumber-in-springboot_cucumber-spring-configuration.java
Created June 17, 2019 01:20
Class to make Cucumber use Spring Context for test scenario execution
package com.arun.cucumber.hello.bdd;
import com.arun.cucumber.hello.Application;
import cucumber.api.java.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.ContextConfiguration;
Feature: Delete Employee
Background:
Given an employee with the following attributes
| id | firstName | lastName | dateOfBirth | startDate | employmentType | email |
| 400 | Rachel | Green | 1990-01-01 | 2018-01-01 | Permanent | rachel.green@fs.com |
And with the following phone numbers
| id | type | isdCode | phoneNumber | extension |
Feature: Update Employee
Background:
Given an employee with the following attributes
| id | firstName | lastName | dateOfBirth | startDate | employmentType | email |
| 300 | Rachel | Green | 1990-01-01 | 2018-01-01 | Permanent | rachel.green@fs.com |
And with the following phone numbers
| id | type | isdCode | phoneNumber | extension |
Feature: Get Employee
Background:
----------------------------------------------------
Here an employee is setup to test get employee by id
----------------------------------------------------
Given an employee with the following attributes
| id | firstName | lastName | dateOfBirth | startDate | employmentType | email |
Feature: Create Employee
Scenario Outline: <testCase> <expectedResult>
-----------------------------------------------
1. Create employee without first name fails.
2. Create employee without last name fails.
... other validations
-----------------------------------------------
Feature: Create Employee
Scenario: WITH ALL REQUIRED FIELDS IS SUCCESSFUL
--------------------------------------------------------------------------------
IMPORTANT NOTE - Field name in Employee.java is used as DataTable column header.
--------------------------------------------------------------------------------
Given user wants to create an employee with the following attributes
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import cucumber.api.java8.En;
import io.cucumber.datatable.DataTable;
import io.restassured.response.Response;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;