Loading...
Loading...
Compare original and translation side by side
┌────────────┐ ┌──────────────┐ ┌───────────┐
│ Steps │ │ Step │ │ │
│ in Gherkin ├──matched with──>│ Definitions ├───manipulates──>│ System │
└────────────┘ └──────────────┘ └───────────┘┌────────────┐ ┌──────────────┐ ┌───────────┐
│ Steps │ │ Step │ │ │
│ in Gherkin ├──matched with──>│ Definitions ├───manipulates──>│ System │
└────────────┘ └──────────────┘ └───────────┘Feature: Short description
Optional multi-line description explaining the feature.
Background:
Given common setup steps for all scenarios
Rule: Business rule grouping (Gherkin 6+)
Scenario: Concrete example illustrating the rule
Given an initial context (past tense, setup)
When an action occurs (present tense, trigger)
Then expected outcome (assertion)
And additional step
But negative assertion
Scenario Outline: Parameterized scenario
Given there are <start> items
When I remove <remove> items
Then I should have <remaining> items
Examples:
| start | remove | remaining |
| 12 | 5 | 7 |
| 20 | 5 | 15 |Feature: Short description
Optional multi-line description explaining the feature.
Background:
Given common setup steps for all scenarios
Rule: Business rule grouping (Gherkin 6+)
Scenario: Concrete example illustrating the rule
Given an initial context (past tense, setup)
When an action occurs (present tense, trigger)
Then expected outcome (assertion)
And additional step
But negative assertion
Scenario Outline: Parameterized scenario
Given there are <start> items
When I remove <remove> items
Then I should have <remaining> items
Examples:
| start | remove | remaining |
| 12 | 5 | 7 |
| 20 | 5 | 15 || Keyword | Purpose | Example |
|---|---|---|
| Setup/precondition | |
| Action/trigger | |
| Assertion/outcome | |
| Continue previous type | |
| Negative continuation | |
| Bullet-style step | |
| 关键字 | 用途 | 示例 |
|---|---|---|
| 初始化/前置条件 | |
| 动作/触发事件 | |
| 断言/预期结果 | |
| 延续同类型步骤 | |
| 反向延续步骤 | |
| 无序列表式步骤 | |
Given the following users exist:
| name | email | role |
| Alice | alice@example.com | admin |
| Bob | bob@example.com | user |Given a blog post with content:
"""markdown
# My Post Title
This is the content of my blog post.
"""Given the following users exist:
| name | email | role |
| Alice | alice@example.com | admin |
| Bob | bob@example.com | user |Given a blog post with content:
"""markdown
# My Post Title
This is the content of my blog post.
"""@smoke @critical
Feature: User authentication
@wip
Scenario: Login with valid credentials
...
@slow @database
Scenario: Bulk user import
...@smoke and not @slow@gui or @api(@smoke or @critical) and not @wip@smoke @critical
Feature: User authentication
@wip
Scenario: Login with valid credentials
...
@slow @database
Scenario: Bulk user import
...@smoke and not @slow@gui or @api(@smoke or @critical) and not @wipGiven('I have {int} cucumbers in my belly') do |count|
@belly = Belly.new
@belly.eat(count)
end
When('I wait {int} hour(s)') do |hours|
@belly.wait(hours)
end
Then('my belly should growl') do
expect(@belly.growling?).to be true
endGiven('I have {int} cucumbers in my belly') do |count|
@belly = Belly.new
@belly.eat(count)
end
When('I wait {int} hour(s)') do |hours|
@belly.wait(hours)
end
Then('my belly should growl') do
expect(@belly.growling?).to be true
endundefinedundefinedconst { Given, When, Then } = require('@cucumber/cucumber');
Given('I have {int} cucumbers in my belly', function(count) {
this.belly = new Belly();
this.belly.eat(count);
});
When('I wait {int} hour(s)', async function(hours) {
await this.belly.wait(hours);
});
Then('my belly should growl', function() {
expect(this.belly.isGrowling()).toBe(true);
});
// With data table
Given('the following users exist:', async function(dataTable) {
for (const row of dataTable.hashes()) {
await User.create(row);
}
});const { Given, When, Then } = require('@cucumber/cucumber');
Given('I have {int} cucumbers in my belly', function(count) {
this.belly = new Belly();
this.belly.eat(count);
});
When('I wait {int} hour(s)', async function(hours) {
await this.belly.wait(hours);
});
Then('my belly should growl', function() {
expect(this.belly.isGrowling()).toBe(true);
});
// With data table
Given('the following users exist:', async function(dataTable) {
for (const row of dataTable.hashes()) {
await User.create(row);
}
});public class StepDefinitions {
@Given("I have {int} cucumbers in my belly")
public void iHaveCucumbersInMyBelly(int count) {
belly = new Belly();
belly.eat(count);
}
@When("I wait {int} hour(s)")
public void iWaitHours(int hours) {
belly.wait(hours);
}
@Then("my belly should growl")
public void myBellyShouldGrowl() {
assertTrue(belly.isGrowling());
}
}public class StepDefinitions {
@Given("I have {int} cucumbers in my belly")
public void iHaveCucumbersInMyBelly(int count) {
belly = new Belly();
belly.eat(count);
}
@When("I wait {int} hour(s)")
public void iWaitHours(int hours) {
belly.wait(hours);
}
@Then("my belly should growl")
public void myBellyShouldGrowl() {
assertTrue(belly.isGrowling());
}
}{int}{float}{word}{string}{}cucumber(s)color/colour{int}{float}{word}{string}{}cucumber(s)color/colourundefinedundefined
```javascript
// JavaScript
const { Before, After } = require('@cucumber/cucumber');
Before(async function(scenario) {
// runs before each scenario
});
After(async function(scenario) {
// runs after each scenario
if (scenario.result.status === 'FAILED') {
await this.screenshot();
}
});
```javascript
// JavaScript
const { Before, After } = require('@cucumber/cucumber');
Before(async function(scenario) {
// runs before each scenario
});
After(async function(scenario) {
// runs after each scenario
if (scenario.result.status === 'FAILED') {
await this.screenshot();
}
});Before('@database') do
DatabaseCleaner.start
end
After('@database') do
DatabaseCleaner.clean
endBefore({ tags: '@browser and not @headless' }, async function() {
this.browser = await launchBrowser();
});Before('@database') do
DatabaseCleaner.start
end
After('@database') do
DatabaseCleaner.clean
endBefore({ tags: '@browser and not @headless' }, async function() {
this.browser = await launchBrowser();
});BeforeAll do
# once before any scenario
end
AfterAll do
# once after all scenarios
endBeforeAll do
# once before any scenario
end
AfterAll do
# once after all scenarios
endWhen "Bob" logs in
Then he sees his dashboardWhen I visit "/login"
And I enter "bob" in "username"
And I enter "secret" in "password"
And I click "Login"
Then I should see "Dashboard"When "Bob" logs in
Then he sees his dashboardWhen I visit "/login"
And I enter "bob" in "username"
And I enter "secret" in "password"
And I click "Login"
Then I should see "Dashboard"undefinedundefinedundefinedundefinedreferences/gherkin-syntax.mdreferences/step-definitions.mdreferences/hooks-config.mdreferences/best-practices.mdreferences/gherkin-syntax.mdreferences/step-definitions.mdreferences/hooks-config.mdreferences/best-practices.md