Important annotations & configurations of Cucumber

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:

  • strict: true/false Fails the execution if any step is undefined or pending
  • monochrome: true/false Displays console output in a readable format

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

  • Given I am on the login page
  • When I enter username "<username>" and password "<password>"
  • Then I should be logged in successfully

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.

Carlos Felix Dorival Esquivel

Quality assurante -MBA- ISTQB

1 个月

Great review about cucumber

回复
Vivek Dixit

Automation QA Lead |BFSI| Guidewire(P&C)| UFT|Selenium |Tosca| Playwright | Cypress| Agile Scrum... etc

2 个月

Very informative

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了