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 expressionsExecuting tests in cucumber
To write the tests using JUnit @RunWith annotation, we need below dependencies. cucumber.api.junit.Cucumber – This class is present in the cucumber-junit artifact library.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
</dependency>
Then you can add below test class. After running the below test, cucumber generates the report at target/selenium-reports. Cucumber.class contains main method that reads the feature file and executes scenario in it.
package org.softpost;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "classpath:abc.feature",
glue = "classpath:org.softpost",
plugin = "html:target/selenium-reports"
)
public class MyTests {
}
Web development and Automation testing
solutions delivered!!