Cucumber Flashcards
What is Cucumber? What is BDD? Why did you decide to start using Cucumber? What is the difference between Cucumber and TestNG?
Cucumber is a tool used for automated acceptance tests in a BDD format. It excels in executing plain-text functional descriptions, written in Gherkin language, as automated tests. BDD involves users, like business analysts and product owners, writing scenarios or tests describing the system’s behavior for review by product owners before developers code. The key strength of Cucumber is its simplicity in explaining requirements in plain English. It facilitates involvement from non-coders, ensuring all stakeholders understand and accept requirements easily. Cucumber prioritizes user experience and supports code reuse. Choosing Cucumber is beneficial because it enables stakeholders, even those unfamiliar with coding, to participate. It places emphasis on user experience and promotes code reusability. Now, comparing TestNG and Cucumber: TestNG is a testing framework for specifying test classes to be executed, while Cucumber runs acceptance tests in a BDD style. Gherkin is the language used by Cucumber to define test cases.
How did you use cucumber in your framework?
the main components are step definitions and feature files. Feature files contain test cases written in Gherkin Language, employing Given, When, Then statements. The automation code is implemented using Selenium and Java. To maintain organization, step definitions are stored in a dedicated folder with the naming convention src/test/java. Simultaneously, feature files reside in a separate folder named src/test/resources. To coordinate test execution, a TestRunner class is created, utilizing JUnit. This class serves as the starting point, collecting and executing all specified tests in the Cucumber framework.
Give an example of a behavior-driven test in plain text?
Author: QA Team Feature: Search Product Background: Given I am on the homepage of the online store And there are products available for search @regression Scenario: Search for a Product When I search for “Laptop” Then I should see a list of available laptops @smoke Scenario: Search for an Out-of-Stock Product When I search for “Out-of-Stock Item” Then I should see a message indicating the product is out of stock
What are the two files required to run a cucumber test?
● A feature file. ● A step definition file.
What is a feature file? What is the extension? What is there in a feature file? What are the keywords used in feature files?
Feature File in Cucumber serves as the entry point for tests, using a Gherkin language like plain English. It is important for automation and also serves as living documentation. Feature files, typically with a .feature extension, start with the “Feature” keyword and can contain scenarios. Keywords like Feature, Scenario, Background, Scenario Outline, Given, When, And, But, and Then are used to define the test steps in Gherkin syntax. An example of a feature file name is “Test.feature.”
What is the language used to write scenarios in a feature file? What is the main purpose?
Gherkin is a plain text language for creating cucumber scenarios in a feature file. It’s a language designed for business understanding, allowing non-programmers to describe software behavior from the user’s viewpoint. While it’s not exclusively for automated tests, its structured nature makes automation possible. Cucumber is the tool that automates these structured tests, and Gherkin files can also serve as project documentation.
Name any 2 testing frameworks that can be integrated with Cucumber?
TestNG ● Junit
Is it mandatory to use Given, When, Then keywords while writing scenario? What is the difference?
While Gherkin keywords are commonly used for readability and consistency in Cucumber feature files, it’s correct that they are not mandatory. Feature: Shopping Cart Scenario: Add Item * User adds item to the cart * Cart should display the added item Scenario: Remove Item * User removes item from the cart * Cart should not contain the removed item In this brief example, asterisks (*) are used to represent the steps, illustrating a more concise syntax. However, for better clarity and consistency, Gherkin keywords are often preferred in practice.
Explain Cucumber Tags? How to run only specific scenarios? How to run multiple scenarios with tags? How to exclude tagged scenarios?
Cucumber tags, represented by @, organize scenarios in feature files and serve multiple purposes. Tags are used to group scenarios, ignore them during execution, and logically combine them using OR and AND conditions, in a feature file for an E-commerce application login, scenarios can be tagged as @SmokeTest or @RegressionTest. To execute specific tags, mention them in the CucumberOptions in the runner class. For example, to execute only the @SmokeTest scenario, use @CucumberOptions(tags=”@SmokeTest”). For multiple tags, use OR or AND conditions, and to skip specific tags, use the ~ symbol. An example is @CucumberOptions(tags=”~@SmokeTest AND @RegressionTest”), meaning execute scenarios tagged as @RegressionTest but not @SmokeTest.
Name any two build management tools that can be integrated with Cucumber?
Gradle ● Maven
What is the use of the keyword “background” in a feature file?
In Cucumber, a Background is used to define a set of common steps for all scenarios within a feature file, providing background. For example, in an “Online Shopping Checkout” feature, the Background ensures the user starts on the shopping website with an empty cart. Scenarios, like adding an item to the cart and removing an item, utilize this common context for testing different conditions, each tagged accordingly.
Explain Cucumber Hooks? What’s Before/After hook?
Cucumber Hooks, marked with @before and @after in Java, simplify the start and finish for scenarios. The given Hooks class handles scenario initiation and completion, captures screenshots on failure, and ensures a smooth workflow. @Before runs before “Background” steps, and @After executes regardless of the scenario’s result.
What is @CucumberOptions in test runner? List the properties of @CucumberOptions
@CucumberOptions are utilized to define specific properties for Cucumber tests, including the feature file path, step definition path, and a boolean value for dry run to check for missing step definitions, it allows grouping scenarios using tags, specifying report formats with the plugin property, and enhancing console output readability with the monochrome boolean value.
What is the difference between scenario and scenario outline?
A Scenario in Cucumber represents a single, specific test case, detailing the exact steps and expected outcomes. Now, a Scenario Outline serves as a template for scenarios. It allows us to define a scenario structure with placeholders for parameters. The actual values for these parameters come from the Examples section associated with the Scenario Outline. This way, we can reuse the same scenario structure with different input data. In simpler terms, a Scenario is a stand-alone test case, while a Scenario Outline is a flexible template that adapts to various scenarios by including different sets of data from the Examples section.
How can we achieve data-driven testing in Cucumber? What is DataTable in Cucumber? DataTable vs Scenario Outline?
for data-driven testing in Cucumber, we can use this thing called DataTable directly in the scenario. It’s like a table right there in the feature file, perfect for scenarios with different input data, if we have a scenario structure that stays the same but the input data changes, we roll with Scenario Outline. It’s like a template scenario where we fill in the blanks with data from the Examples section.