Cucumber + Java
Introduction to Cucumber Installation of CucumberAdding Cucumber dependency to Java project Writing first cucumber test Executing Cucumber tests using Cucumber class Cucumber options Tagging the scenarios Using name option Passing parameters to steps Key – Value pair Datatable Multiple column datatable in Cucumber Scenario Background Scenario outline Running multiple feature files in Cucumber Sharing selenium Webdriver instance using PicoContainer Embedding the screenshot Writing to Cucumber HTML reports Cucumber dependency for using Lambda expressions in Java 8 Cucumber test using Lambda expressionsLambda expressions in cucumber
Now let us write sample cucumber step definitions using Lambda expressions. Here is the sample feature file.
Feature: Lambda feature
Scenario: Verify sum
Given I add 1 and 2
Then I verify that sum is 3
Here is the sample Test Class using Lambda expressions to write the step definitions. Note that StepClass must implement cucmber.api.java8.En interface and step methods should be inside the constructor of test class. You also need to ensure that Java language level should be 1.8.
package org.softpost;
import cucumber.api.java8.En;
public class StepClass8 implements En {
public StepClass8() {
Given("^I add 1 and 2$", () -> {
System.out.println("Adding 1 and 2");
});
Then("^I verify that sum is 3$", () -> {
System.out.println("Checking that sum is 3");
});
}
}
If you are using Maven, you can specify the Java language level using below XML section in POM.XML
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
Web development and Automation testing
solutions delivered!!