Appearance
Allure Behat reference
These are the attributes and methods that you can use to integrate your Behat tests with Allure Report.
Severity
Set the test's severity.
To enable this, specify the severity_key
configuration option. Use this key as a prefix in the Gherkin tags, followed by one of the values: “trivial”, “minor”, “normal”, “critical”, or “blocker”.
The example below assumes that you use have configured severity:
as the prefix.
gherkin
Feature: Labels
@severity:critical
Scenario: Create new label for authorized user
When I open labels page
And I create label with title "hello"
Then I should see label with title "hello"
Link
Add links related to the test via Gherkin tags. Two types of links are supported: issue links and TMS links.
To enable this, specify the issue_tag_prefix
and test_id_tag_prefix
configuration options.
The example below assumes that you use have configured issue:
and tms:
as the prefixes.
gherkin
Feature: Labels
@issue:https://issues.example.org/AUTH-123
@tms:https://tms.example.org/TMS-456
Scenario: Create new label for authorized user
When I open labels page
And I create label with title "hello"
Then I should see label with title "hello"
Behavior-based hierarchy
Any Gherkin tag is considered the test's user story for the Allure's behavior-based hierarchy, unless the tag has a known prefix or is ignored, according to the configuration.
gherkin
@UI @Labels
Feature: Labels
Scenario: Create new label for authorized user
When I open labels page
And I create label with title "hello"
Then I should see label with title "hello"
Test sub-steps
StepSupport::executeStep($name, $logic, $title = null)
To split a Gherkin step into smaller sub-steps:
In your context class, add the
StepSupport
trait.In the step implementation, pass a lambda function or a method reference to
$this->executeStep()
.The function or method should accept no arguments. During the execution of a sub-step, you can call
$this->executeStep()
again to split it into more sub-steps.
php
use Behat\Behat\Context\Context;
use Yandex\Allure\Adapter\Support\StepSupport;
class MyContext implements Context
{
use StepSupport;
/**
* @When I go to the registration form
*/
public function goToRegistrationForm()
{
$this->executeStep('Step 1', [$this, 'step1']);
$this->executeStep('Step 2', [$this, 'step2']);
}
public function step1()
{
$this->executeStep('Step 1.1', function () {
// ...
});
$this->executeStep('Step 1.2', function () {
// ...
});
}
public function step2()
{
$this->executeStep('Step 2.1', function () {
// ...
});
$this->executeStep('Step 2.2', function () {
// ...
});
}
}
Parametrized tests
In Gherkin, a Scenario Outline
(or a Scenario Template
) implements the parametrized tests pattern. A scenario outline must contain an Examples
table, from which Behat loads sets of parameters, one row after another. Behat runs all the outline's steps multiple times — one per each set of parameters.
The example below shows a Gherkin file and a PHP implementation file of a test. In this example, In the test report, this test will include the three steps executed with the first set of parameter, then the three steps executed with the second set of parameters.
gherkin
Feature: User management
Scenario Outline: Registration
When I go to the registration form
And I enter my details: "<login>", "<password>", "<name>", "<birthday>"
Then the profile should be created
Examples:
| login | password | name | birthday |
| johndoe | qwerty | John Doe | 1970-01-01 |
| janedoe | 123456 | Jane Doe | 1111-11-11 |
php
use Behat\Behat\Context\Context;
class MyContext implements Context
{
/**
* @When I go to the registration form
*/
public function goToRegistrationForm()
{
}
/**
* @When I enter my details: :login, :password, :name, :birthday
*/
public function enterDetails($login, $password, $name, $birthday)
{
}
/**
* @When I go to the registration form
*/
public function profileShouldBeCreated()
{
}
}
Attachments
AttachmentSupport::addAttachment($filePathOrContents, $caption, $type = null)
To create an attachment, add the AttachmentSupport
trait to your context class and call $this->addAttachment()
at any point during your test. Pass either the content string or the path from which the data will be read.
To ensure that the reader's web browser will display attachments correctly, it is recommended to specify each attachment's type. To do so, pass the media type of the content as $type
. The media type affects how the data will be displayed in the test report, while the filename extension is appended to the filename when user wants to save the file. If not specified, Allure Behat will try to guess the type automatically based on the contents.
php
use Behat\Behat\Context\Context;
use Yandex\Allure\Adapter\Support\AttachmentSupport;
class MyContext implements Context
{
use AttachmentSupport;
/**
* @When I go to the registration form
*/
public function profileShouldBeCreated()
{
$this->addAttachment('/path/to/image.png', 'Screenshot', 'image/png');
}
}