Gherkin
Convert Gherkin scenarios to TestDriver prompts
This guide explains how to convert Gherkin scenarios into TestDriver prompts for use in your testing workflows. By following this process, you can easily adapt existing Gherkin test cases into a format compatible with TestDriver.
What’s Gherkin?
Gherkin is a plain-text language used to describe test scenarios in a human-readable format. It uses keywords like Given
, When
, Then
, and And
to define steps in a test.
Example Gherkin scenario:
What are TestDriver prompts?
TestDriver prompts are high-level instructions that describe what the AI should do. They’re written in plain text and focus on user actions or expected outcomes.
Example prompts:
Steps to convert Gherkin to TestDriver prompts
Step 1: Understand the mapping
Gherkin Keyword | TestDriver Prompt |
---|---|
Given | Describes the initial state or setup. |
When | Describes the user action. |
Then | Describes the expected outcome or result. |
And | Adds additional steps to the same context. |
Step 2: Extract steps from Gherkin
Take each step from the Gherkin scenario and rewrite it as a plain-text prompt. Remove the Given
, When
, Then
, and And
keywords, and focus on the action or expectation.
Example:
Gherkin Step | TestDriver Prompt |
---|---|
Given the user is on the login page | the user is on the login page |
When the user enters valid credentials | the user enters valid credentials |
And clicks the "Log In" button | clicks the "Log In" button |
Then the user should see the dashboard | the user should see the dashboard |
Step 3: Write the prompts in YAML format
Combine the extracted prompts into a YAML file. Each step should be written as a prompt
entry.
Example YAML:
Step 4: Save the YAML file
- Save the YAML content to a file (for example,
login_test.yaml
). - Ensure the file is stored in the appropriate directory for your TestDriver project (for example,
testdriver/
).
Step 5: Run the test with TestDriver
Use the TestDriver CLI to execute the test.
Command:
Example: Full conversion workflow
Input Gherkin scenario:
Converted YAML:
Run the test:
Best practices
- Keep Prompts Simple: Focus on high-level actions or outcomes. Avoid including unnecessary details.
- Use Descriptive Prompts: Ensure each prompt clearly describes the action or expectation.
- Test the YAML: Run the converted YAML file to verify that it works as expected.
- Organize Files: Store YAML files in a structured directory (for example,
testdriver/
) for easy management.
By following this guide, you can efficiently convert Gherkin scenarios into TestDriver prompts, enabling seamless integration of existing test cases into your TestDriver workflows.