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 expressionsTaking screenshot in selenium in cucumber
When working in a selenium automation project, we often need to take a screenshot on test failure. Selenium API provides a way to take screenshot with the help of takesScreenshot interface. Cucumber allows you to embed that screenshot in the Cucumber reports. Here is the simple code.
@After("@selenium")
public void killBrowser(Scenario scenario){
if (scenario.isFailed()) {
scenario.embed(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES), "image/png");
}
driver.close();
driver.quit();
}
Below image shows where to find the HTML report in Maven project.Here is the sample HTML report showing the captured screenshot.Web development and Automation testing
solutions delivered!!