Important annotations & configurations of Cucumber
@Given
Denotes a precondition before a scenario
Ex: @Given("I have a valid login credential") public void valid_login_credential() { //Code }
@When
Denotes an action or event that occurs
Ex: @When("I enter username and password") public void enter_username_and_password() { //Code}
@Then
Denotes the expected outcome of a scenario
Ex: @Then("I should be logged in successfully") public void i_logged_in_successfully() { //Code }
@Before
Denotes actions to be performed before each scenario
Ex: @Before public void setup() { //Initialisation Code }
@After
Denotes actions to be performed after each scenario
Ex: @After public void teardown() { //Cleanup code }
Background
Executes a set of steps before each scenario in a feature file
Ex: @Background public void user_is_on_homepage() { //Code }
@AfterStep
Denotes actions to be performed after each step
Ex: @AfterStep public void takeScreenshotAfterStep(Scenario scenario) { //Code }
@BeforeStep
Denotes actions to be performed before each step.
Ex: @BeforeStep public void logStepExecution(Scenario scenario) { // Implementation goes here }
@CucumberOptions: Allows configuring Cucumber options
Ex: @CucumberOptions
领英推荐
(
features = "src/test/resources/features", ?glue = {"step_definitions"}, plugin = {"pretty", "html:target/cucumber-reports"}, tags = "@smokeTest", strict = true, dryRun = false
)
features: Defines the location of feature files
glue: Specifies the location of step definition files
plugin: Defines plugins for generating reports
tags: Filters scenarios to be executed based on tags
dryRun: Verifies whether all step definitions have corresponding glue code
More Configs:
Data Tables
Scenario: Add multiple users
Given I am on the user management page
When I add the following users:
| Name | Email | Role |
| John Doe | [email protected] | Admin |
Meaning: In the scenario, we use a data table to provide multiple sets of data for adding users, each row in the data table represents a set of user details.
Scenario Outline:
Scenario Outline: Valid Login
Examples:
| username | password |
| user1 | password1 |
We use a scenario outline to define a template scenario with placeholders <username> and <password>, the scenario outline is followed by an examples table.
Feel free to add anything that we might have missed.
Quality assurante -MBA- ISTQB
1 个月Great review about cucumber
Automation QA Lead |BFSI| Guidewire(P&C)| UFT|Selenium |Tosca| Playwright | Cypress| Agile Scrum... etc
2 个月Very informative