Cucumber Flashcards

1
Q

What is Cucumber? What is BDD? Why did you decide to start using Cucumber? What is the difference between Cucumber and TestNG?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How did you use cucumber in your framework?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example of a behavior-driven test in plain text?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two files required to run a cucumber test?

A

● A feature file. ● A step definition file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a feature file? What is the extension? What is there in a feature file? What are the keywords used in feature files?

A

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.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the language used to write scenarios in a feature file? What is the main purpose?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Name any 2 testing frameworks that can be integrated with Cucumber?

A

TestNG ● Junit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is it mandatory to use Given, When, Then keywords while writing scenario? What is the difference?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain Cucumber Tags? How to run only specific scenarios? How to run multiple scenarios with tags? How to exclude tagged scenarios?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Name any two build management tools that can be integrated with Cucumber?

A

Gradle ● Maven

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the use of the keyword “background” in a feature file?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain Cucumber Hooks? What’s Before/After hook?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is @CucumberOptions in test runner? List the properties of @CucumberOptions

A

@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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between scenario and scenario outline?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can we achieve data-driven testing in Cucumber? What is DataTable in Cucumber? DataTable vs Scenario Outline?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When in Cucumber some test scenarios fail and now you want to run failed ones, how would you do it?

A

In the updated TestRunner class, I’ve included the “re-run:target/rerun.txt” configuration within the plugins to track and address any failed scenarios. Additionally, a new FailedRunner class has been introduced specifically to rerun those identified failed scenarios listed in the “rerun.txt” file, developing our troubleshooting capabilities.

17
Q

Let’s say I have a Google app and in a Cucumber file I have 20 scenarios and there are 2 steps that are all common for all scenarios. How can I achieve that without repeating the code?

A

Using background keyword

18
Q

In cucumber I have scenario with 10 steps and let’s say step #5 I want to execute 5 times. How can I do it?

A

Using DataTable