0% found this document useful (0 votes)
44 views12 pages

Cucumber Frameworks FAQ

BDD

Uploaded by

mif mif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views12 pages

Cucumber Frameworks FAQ

BDD

Uploaded by

mif mif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 01)

1. What is Cucumber, and why is it used in test automation?

- Cucumber is a tool for Behavior-Driven Development (BDD) that allows testers and
developers to define test cases in a plain language format, making tests readable and
understandable by non-technical stakeholders.

2. Explain what Gherkin is in Cucumber.

- Gherkin is the syntax used in Cucumber to define test cases in a human-readable


format. It allows defining test scenarios in a Given-When-Then structure, making test
cases clear and aligned with business requirements.

3. What are feature files in Cucumber?

- Feature files are plain text files containing Cucumber tests written in Gherkin syntax.
Each feature file has one or more scenarios that describe the expected behavior of the
application.

4. Describe the structure of a Cucumber scenario.

- A Cucumber scenario typically follows the Given-When-Then structure, where Given


defines the initial state, When represents actions or events, and Then specifies the
expected outcome.

5. What are tags in Cucumber, and how are they used?

- Tags are used to categorize scenarios or feature files in Cucumber. They allow selective
execution of tests based on specific tags like @Smoke or @Regression by running only
the tests marked with those tags.

6. How do you execute specific scenarios in Cucumber?

- Specific scenarios can be executed by using tags. By assigning tags to scenarios and
then specifying those tags in the Cucumber options, only the tagged scenarios will run.

7. What are step definitions in Cucumber?

- Step definitions are the actual implementation of Cucumber steps, linking Gherkin
steps to code. They contain the code that executes when a corresponding Gherkin step
is matched during the test.

8. How does Cucumber handle parameterization in test steps?

- Cucumber allows parameterization by using placeholders in Gherkin steps,


represented by double quotes. Parameters can be extracted in step definitions and used
dynamically in the tests.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 01)

9. Explain the purpose of Background in Cucumber.

- Background is used to define common steps for all scenarios within a feature file,
avoiding repetition by specifying preconditions that apply to every scenario in the file.

10. What is the role of Examples in Cucumber?

- Examples are used in scenario outlines to provide multiple sets of test data for the
same scenario, enabling data-driven testing by executing the scenario multiple times
with different data values.

11. Describe what Scenario Outline is in Cucumber.

- Scenario Outline is a way to run the same scenario multiple times with different sets of
data. It is used with the Examples keyword to provide various input combinations for a
single scenario.

12. How can you perform data-driven testing in Cucumber?

- Data-driven testing is achieved using Scenario Outline and Examples. Each row in the
Examples table represents a different data set, allowing the scenario to run with various
inputs.

13. Explain the use of hooks in Cucumber.

- Hooks are used to define code blocks that run before or after scenarios. Cucumber
provides @Before and @After hooks for setup and teardown tasks in test execution.

14. What is the difference between @Before and @BeforeStep hooks?

- @Before hooks run before each scenario, while @BeforeStep hooks execute before
each step within a scenario, allowing setup actions at both the scenario and step levels.

15. How do you integrate Cucumber with JUnit or TestNG?

- Cucumber can be integrated with JUnit or TestNG by adding the Cucumber


dependencies for these frameworks in the project. Cucumber tests can then be run
using JUnit or TestNG test runners.

16. What is the purpose of the glue option in Cucumber?

- The glue option specifies the package where Cucumber should look for step definitions
and hooks, linking Gherkin steps with the corresponding Java code.

17. Describe the purpose of the dryRun option in Cucumber.

- The dryRun option is used to check if all Gherkin steps have corresponding step
definitions without actually executing the tests, helping to identify missing step
implementations.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 01)

18. What is the use of monochrome option in Cucumber?

- The monochrome option in Cucumber formats console output to make it more


readable by removing extraneous characters and providing a cleaner, simpler output.

19. How can you generate reports in Cucumber?

- Cucumber can generate reports in formats like HTML, JSON, and XML. Reporting
plugins can be added, such as Cucumber Reports or Extent Reports, to create detailed
test execution summaries.

20. Explain the difference between Scenario and Scenario Outline.

- Scenario defines a single test case with specific inputs, while Scenario Outline is used
to run the same scenario with multiple data sets, allowing parameterization through the
Examples table.

21. What is the use of regex in step definitions?

- Regular expressions (regex) are used in step definitions to capture dynamic values
from Gherkin steps, allowing flexible matching of step patterns and handling
parameterized inputs.

22. How do you handle dependency injection in Cucumber?

- Dependency injection in Cucumber can be handled using libraries like PicoContainer,


allowing sharing of state and objects across step definitions within the same scenario.

23. Describe what a custom parameter type is in Cucumber.

- Custom parameter types in Cucumber allow defining specific patterns for data types in
step definitions, enabling the conversion of complex data formats into Java objects.

24. How does Cucumber support parallel test execution?

- Cucumber supports parallel test execution through plugins like the Cucumber-JVM
parallel plugin or by configuring TestNG/JUnit to run tests in parallel, enhancing
execution speed.

25. Explain the purpose of the `@CucumberOptions` annotation.

- The @CucumberOptions annotation configures various runtime options for Cucumber,


such as specifying the path to feature files, glue, tags, and report formats, providing
customization for test execution.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 01)

26. What is a Feature file path in Cucumber?

- The feature file path is the location where feature files are stored within a project. It is
specified in the @CucumberOptions annotation to tell Cucumber where to look for
feature files during test execution.

27. What is Cucumber Expressions, and how does it differ from regex?

- Cucumber Expressions are a simpler alternative to regex for matching steps. They
allow defining parameterized steps without complex regex syntax, making steps easier
to read and maintain.

28. How do you ignore scenarios in Cucumber?

- Scenarios can be ignored by tagging them with @Ignore or by excluding specific tags in
the @CucumberOptions. This allows selective execution by skipping unwanted
scenarios.

29. What is the purpose of ScenarioContext in Cucumber?

- ScenarioContext is used to share data between step definitions within the same
scenario, storing key-value pairs to access shared data across multiple steps.

30. How does Cucumber support BDD principles?

- Cucumber supports BDD by allowing test cases to be written in a plain language


format, facilitating collaboration between business stakeholders, developers, and
testers through clear, readable test scenarios.

31. Explain the concept of Dependency Injection in Cucumber using PicoContainer.

- PicoContainer allows injecting dependencies across step definitions in Cucumber,


helping to maintain shared data and objects throughout the scenario lifecycle without
using static variables.

32. How can you handle dynamic data in Cucumber?

- Dynamic data can be managed using parameters in step definitions or by fetching data
from external sources like databases or APIs during test execution.

33. What is DataTable in Cucumber, and how is it used?

- DataTable is used to pass multiple rows of data into Cucumber steps. It can be used to
create test data tables within scenarios, allowing structured data input and access in
step definitions.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 01)

34. How can you read data from external files in Cucumber?

- External data can be read in Cucumber by using Java libraries to access files like CSV,
Excel, or JSON and using the data within step definitions to perform data-driven testing.

35. Explain how to write reusable step definitions in Cucumber.

- Reusable step definitions can be achieved by using parameters and generic


expressions in steps, allowing multiple Gherkin steps to match a single, flexible step
definition.

36. What is a step definition file path, and how do you specify it?

- The step definition file path is the package location of step definition files. In
@CucumberOptions, the glue option specifies this path to connect Gherkin steps with
the Java code.

37. How can you run multiple feature files in Cucumber?

- Multiple feature files can be run by specifying the directory path in the
@CucumberOptions or by specifying multiple feature files in the test runner
configuration.

38. Describe the purpose of Scenario Hooks in Cucumber.

- Scenario Hooks like @Before and @After are used to execute setup and cleanup
actions around each scenario, helping manage preconditions and post-conditions
automatically.

39. How do you use BeforeAll and AfterAll hooks in Cucumber?

- BeforeAll and AfterAll hooks are used for one-time setup and teardown actions that
run only once for all scenarios, such as initializing connections or loading
configurations.

40. How can you handle exceptions in Cucumber step definitions?

- Exceptions can be handled by using try-catch blocks in step definitions. Alternatively,


logging and assertions can capture errors, making it easier to debug test failures.

41. What is the difference between the dryRun and strict options in Cucumber?

- The dryRun option checks for missing step definitions without executing tests, while
the strict option fails the test execution if any step definitions are undefined.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 01)

42. How can you control execution order of Cucumber scenarios?

- Execution order in Cucumber can be controlled using tags and prioritizing scenarios.
External tools like TestNG can also specify the order when running scenarios.

43. What is the purpose of the format option in Cucumber?

- The format option in Cucumber defines the output format of the test results, such as
HTML, JSON, or XML, making it easier to review and analyze test execution results.

44. How can you convert a DataTable to a List or Map in Cucumber?

- Cucumber’s DataTable has built-in methods to convert data into lists or maps. This
allows easy access to structured data for further processing in tests.

45. Describe the purpose of the Cucumber-JVM plugin.

- The Cucumber-JVM plugin allows Cucumber to be used within a JVM-based


environment, supporting integration with JUnit or TestNG and enabling report
generation and parallel execution.

46. What is the use of `@AfterStep` hook in Cucumber?

- The @AfterStep hook is executed after each step within a scenario, allowing actions
like taking screenshots or logging step-level information for detailed reporting.

47. How can you handle multiline arguments in Cucumber?

- Multiline arguments in Cucumber, such as DataTables or doc strings, allow passing


complex data structures into steps, enabling parameterized and flexible tests.

48. Explain the `@CucumberOptions(features = "classpath:features")` syntax.

- The @CucumberOptions syntax specifies the feature file location, where Cucumber
will look for feature files to execute. The classpath indicates that feature files are stored
in the project’s resources folder.

49. What is the purpose of `glue` in `@CucumberOptions`?

- The glue option specifies the package path where Cucumber should search for step
definitions and hooks, linking feature files with the corresponding Java code.

50. How do you implement scenario retry in Cucumber?

- Scenario retry can be implemented using custom code to rerun failed scenarios, often
by integrating with TestNG or a similar framework to manage retries based on test
failures.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 02)

51. How can you handle conditional steps in Cucumber?

- Conditional steps can be handled by using if-else logic within the step definitions,
enabling execution of steps based on specific conditions or values.

52. What is Background in Cucumber, and how is it used?

- Background is a section in a feature file used to define common preconditions for all
scenarios in a feature. It executes before each scenario, simplifying repetitive setup
steps.

53. Explain Scenario Outline in Cucumber.

- Scenario Outline is used to run the same scenario multiple times with different sets of
data. It uses the Examples keyword to provide different data inputs for parameterized
testing.

54. How do you execute specific Cucumber scenarios by name?

- Specific scenarios can be executed by including their names in the command line or
IDE’s test runner, matching the exact scenario titles defined in the feature file.

55. What are the best practices for writing Cucumber feature files?

- Best practices include using clear and concise language, avoiding technical jargon,
following the Gherkin structure, keeping steps simple, and using tags for grouping.

56. How can you run multiple Cucumber tags at once?

- Multiple tags can be run by specifying them in the @CucumberOptions. You can
include or exclude tags by using expressions like `@Tag1 and @Tag2` or `@Tag1 or
@Tag2`.

57. What is the purpose of `cucumber.yml`?

- `cucumber.yml` is a configuration file in Cucumber that stores predefined profiles for


running tests. It helps customize test executions by defining specific settings for each
profile.

58. How can you capture screenshots on test failure in Cucumber?

- Screenshots can be captured on test failure by adding code to the @After hook, which
checks the test result status and takes a screenshot if the scenario fails.

59. How can you organize feature files and step definitions in a large Cucumber project?

- Feature files can be organized by modules or functionality, and step definitions can be
organized by feature or scenario, grouping related steps together for maintainability.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 02)

60. How do you measure Cucumber test coverage?

- Cucumber test coverage can be measured by tracking which scenarios and steps are
executed, using tools like Cucumber reports, or integrating with coverage tools for code-
level metrics.

61. Explain `@BeforeStep` and `@AfterStep` hooks in Cucumber.

- The @BeforeStep and @AfterStep hooks execute actions before and after each step
within a scenario, commonly used for logging or capturing screenshots.

62. How can you handle timeouts in Cucumber?

- Timeouts can be managed by setting explicit or implicit waits within step definitions
or using tools that handle test-level timeouts for more controlled execution.

63. How can you run Cucumber tests in parallel?

- Cucumber tests can be run in parallel by using the Cucumber-JVM parallel plugin,
configuring test runners, or integrating with frameworks like TestNG that support
parallel execution.

64. What are glue paths, and how do they affect Cucumber test execution?

- Glue paths define where Cucumber searches for step definitions, hooks, and other
components. They help locate and execute relevant Java code for specific feature files.

65. How can you filter steps based on tags using CucumberOptions?

- Tags can be filtered in the @CucumberOptions by using the `tags` attribute to include
or exclude certain tags, allowing selective execution of scenarios.

66. Describe how you handle external configuration in Cucumber.

- External configuration, like environment variables or property files, can be accessed in


Cucumber step definitions to set up data, URLs, or parameters dynamically during
execution.

67. What is the difference between the scenario and scenario outline in Cucumber?

- A scenario runs a single instance with a fixed set of data, while a scenario outline uses
placeholders with the Examples table to execute the same scenario with multiple data
sets.

68. How can you implement custom reports in Cucumber?

- Custom reports in Cucumber can be implemented by integrating reporting libraries


like Allure or Extent Reports, customizing the test runner to generate desired formats
and details.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 02)

69. What is `@CucumberOptions(plugin = "json:target/cucumber.json")` used for?

- This option specifies the report type and location for test results. In this case, it
generates a JSON report at the specified location, which can be used for further analysis
or custom reporting.

70. How do you share data between steps in Cucumber?

- Data can be shared between steps using ScenarioContext or a similar structure to store
values in one step and retrieve them in subsequent steps.

71. How do you use `Scenario.getSourceTagNames()` in Cucumber?

- `Scenario.getSourceTagNames()` retrieves the tags applied to the scenario, allowing


custom actions or conditions based on the tags present.

72. Explain the use of `@DataTableType` in Cucumber.

- `@DataTableType` is an annotation used to define custom transformations for


DataTables, converting data into objects or lists as required by the scenario.

73. How can you handle duplicate step definitions in Cucumber?

- Duplicate step definitions can be avoided by organizing and reusing steps carefully. If
duplicates occur, they should be merged or refactored to prevent conflicts.

74. How can you use Cucumber with multiple languages in the same project?

- Cucumber supports multiple languages by configuring each feature file with a different
language header or using separate feature files for different languages within the
project.

75. How do you handle random test data generation in Cucumber?

- Random data can be generated by using libraries like Faker in Java, with the generated
data assigned to variables or stored in ScenarioContext for consistent use across steps.

76. How do you handle data-driven testing in Cucumber?

- Data-driven testing in Cucumber is managed using Scenario Outline with Examples


tables or by loading data from external sources like CSV or JSON files.

77. Can you explain what a Step Definition file is in Cucumber?

- A Step Definition file links the steps in feature files to Java code. It contains methods
with annotations that match each step’s text, allowing the steps to execute specific
actions.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 02)

78. How do you integrate Cucumber with Selenium WebDriver?

- Cucumber integrates with Selenium WebDriver by writing step definitions that include
Selenium code for interacting with the web application, allowing automated browser-
based tests.

79. Explain `@DataTable` in Cucumber.

- `@DataTable` allows passing a table of data from a feature file to a step definition,
which can be converted into lists or maps, enabling multiple data values in one step.

80. How can you skip a scenario in Cucumber?

- A scenario can be skipped by tagging it with `@Skip` or any other tag and configuring
@CucumberOptions to exclude that tag from execution.

81. What are custom parameter types in Cucumber?

- Custom parameter types are defined using the `@ParameterType` annotation, allowing
custom conversions of step arguments, such as converting text to a specific data type.

82. How can you handle exceptions in Cucumber step definitions?

- Exceptions in step definitions can be handled by using try-catch blocks or throwing


custom exceptions, and defining error-handling logic as needed within each step.

83. Explain how hooks are prioritized in Cucumber.

- Hooks can be prioritized by specifying order values in the `@Before` and `@After`
annotations. Lower values run first for @Before hooks and last for @After hooks.

84. What is Cucumber Dry Run?

- A dry run in Cucumber is a mode that checks if all steps in the feature file have
matching step definitions, without actually executing the steps.

85. How do you manage dependencies in a Cucumber project?

- Dependencies in a Cucumber project are managed by using build tools like Maven or
Gradle, which define and download required libraries such as Cucumber, Selenium, or
JUnit.

86. What is the use of `@Monochrome` in Cucumber?

- `@Monochrome` is an option in Cucumber that formats the console output to be more


readable by removing color codes, making it suitable for plain text display.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 02)

87. How can you execute only failed scenarios in Cucumber?

- Failed scenarios can be re-executed by configuring Cucumber to generate a rerun file


that lists failed scenarios, which can then be used to run only those specific tests.

88. Describe how Cucumber integrates with Jenkins.

- Cucumber integrates with Jenkins by configuring Jenkins jobs to execute Cucumber


tests and generate reports. Cucumber plugins can be used for detailed report generation
within Jenkins.

89. What is `@CucumberOptions(strict = true)` used for?

- This option causes Cucumber to treat undefined or pending steps as failures, ensuring
that all steps are implemented before considering a test run successful.

90. How do you use examples in Scenario Outline?

- Examples in Scenario Outline provide multiple sets of data for parameterized testing.
Each row in the Examples table corresponds to one execution of the scenario with
different inputs.

91. Explain `@BeforeAll` and `@AfterAll` in Cucumber.

- `@BeforeAll` and `@AfterAll` run before or after all tests within a test suite, commonly
used for setup or teardown tasks that need to happen once, like database connections.

92. How do you use Background with Scenario Outline?

- Background can be used with Scenario Outline to set up common preconditions before
each example. Background steps execute once per scenario, regardless of the outline
data.

93. How can you customize the Cucumber HTML report?

- Cucumber HTML reports can be customized by adding metadata, integrating plugins


like Allure, or using tools that enhance the report layout and include additional details
like screenshots.

94. What are glue codes in Cucumber?

- Glue code is the Java code in step definition files that implements the actions described
in feature file steps, connecting Cucumber’s feature steps with the underlying code.

95. How can you perform parallel execution in Cucumber with TestNG?

- Parallel execution with TestNG is configured by specifying `parallel = true` in the test
suite XML file, allowing Cucumber scenarios to run concurrently using TestNG.

PDF prepared by Ram Sharan Follow me on Linkedin


100 CUCUMBER INTERVIEW QUESTIONS AND ANSWERS (PART 02)

96. How do you specify a timeout for a step in Cucumber?

- Timeouts for steps can be set by adding a timeout parameter in the `@Given`,
`@When`, or `@Then` annotations, defining the maximum execution time for that step.

97. How does Cucumber handle undefined steps?

- Cucumber will skip undefined steps by default and provides suggestions for step
definitions. Undefined steps can be treated as failures by setting `strict = true` in
CucumberOptions.

98. How can you convert DataTable to a list of custom objects in Cucumber?

- DataTable can be converted to a list of custom objects using the `asList` or `asMaps`
method in the step definition, specifying a custom class for object mapping.

99. How does Cucumber support multiple feature files?

- Cucumber allows specifying multiple feature files or a directory path in the test
runner, running all matching feature files in the specified location.

100. Explain how to handle dynamic test data in Cucumber.

- Dynamic test data in Cucumber can be handled by generating or modifying data at


runtime within the step definitions, using tools like Faker or environment variables for
flexibility.

PDF prepared by Ram Sharan Follow me on Linkedin

You might also like