Cucumber Annotation With Concepts
Cucumber Annotation With Concepts
1. @Given
Syntax:
2. @When
Usage: Used to describe an event that triggers a change in the state of the application.
Syntax:
3. @Then
Usage: Defines the expected behavior of the system after the action has been performed.
Syntax:
4. @And
Usage: Helps to keep the steps concise and readable by combining steps.
Syntax:
5. @But
Syntax:
Cucumber Hooks
1. @Before
Usage: Used for setup activities, like initializing browser instances or setting test data.
Syntax:
@Before
2. @After
Usage: Used for cleanup activities, like closing the browser or clearing test data.
Syntax:
@After
3. @BeforeStep
Usage: Can be used for logging or performing actions before each step.
Syntax:
@BeforeStep
4. @AfterStep
Usage: Can be used for logging or taking screenshots after each step.
Syntax:
@AfterStep
1. Data Tables
Explanation: Used to pass multiple data values in a structured format (like a table).
Syntax:
gherkin
Copy code
| username | password |
| user1 | pass1 |
| user2 | pass2 |
1. Scenario Outline
Explanation: Used to run the same scenario with different sets of data.
Syntax:
Examples:
| username | password |
| user1 | pass1 |
| user2 | pass2 |
Cucumber Tags
1. Tags
Syntax:
@smoke
Scenario: User login
Usage: Use plugins like Cucumber Reporting or ExtentReports for generating reports.
Syntax: Add the necessary dependencies in your pom.xml for Maven projects or build.gradle
for Gradle projects.
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>5.7.0</version>
</dependency>
1. JUnit Runner
Syntax:
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
2. TestNG Runner
Syntax:
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
Cucumber Options
1. CucumberOptions
Syntax:
@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions",