Allure Jasmine reference
These are the functions that you can use to integrate your Jasmine tests with Allure.
Metadata
Assign a test's description, links and other metadata.
Description
allure.description(markdown: string): Promise<void>
Set the test's description. Markdown formatting is allowed. Any HTML formatting, if present, will be stripped for security purposes.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.description(
"This test attempts to log into the website using a login and a password. Fails if any error happens.\n\nNote that this test does not test 2-Factor Authentication.",
);
// ...
});
});
Owner
allure.owner(owner: string): Promise<void>
Set the test's owner.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.owner("John Doe");
// ...
});
});
Tag
allure.tag(tag: string): Promise<void>
Set the test's tags.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.tag("web interface");
await allure.tag("authentication");
// ...
});
});
Severity
allure.severity(severity: string): Promise<void>
Set the test's severity.
The value must be a constant from the Severity
class.
TypeScriptimport { allure } from "./helpers/setup";
import { Severity } from "allure-jasmine";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.severity(Severity.CRITICAL);
// ...
});
});
Label
allure.label(name: string, value: string): Promise<void>
Set an arbitrary label for the test. This is the underlying implementation for a lot of Allure's other functions.
The first argument of the function is the label name. It can be any string.
You can call label()
multiple times to create an array of values under the given name.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.label("my custom label", "value");
// ...
});
});
ID
allure.id(allureId: string): Promise<void>
Set the test's ID.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.id("123");
// ...
});
});
Link
allure.link(url: string, name?: string, type?: string): Promise<void>
allure.issue(name: string, url: string): Promise<void>
allure.tms(name: string, url: string): Promise<void>
Add a link related to the test.
The name
will be used as the link's text. If it is omitted, the full URL will be used instead.
The type
affects the icon that is displayed next to the link in the test report. For convenience, Allure provides two shorthand functions with pre-selected link types: issue
and tms
.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.link("https://dev.example.com/", "Website");
await allure.issue("AUTH-123", "https://issues.example.com/AUTH-123");
await allure.tms("TMS-456", "https://issues.example.com/TMS-456");
// ...
});
});
Behavior-based hierarchy
allure.epic(epic: string): Promise<void>
allure.feature(feature: string): Promise<void>
allure.story(story: string): Promise<void>
Assign names of epics, features or user stories for a test, as part of Allure's behavior-based hierarchy.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.epic("Web interface");
await allure.feature("Essential features");
await allure.story("Authentication");
// ...
});
});
Suite-based hierarchy
allure.parentSuite(name: string): Promise<void>
allure.suite(name: string): Promise<void>
allure.subSuite(name: string): Promise<void>
Assign the name of suite, as part of Allure's suite-based hierarchy.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.parentSuite("Tests for web interface");
await allure.suite("Tests for essential features");
await allure.subSuite("Tests for authentication");
// ...
});
});
Test steps
allure.step(name: string, body: (step?: AllureCommandStepExecutable) => void): Promise<void>
Define a test sub-step with the given name
.
The step()
function is asynchronous, and it accepts an asynchronous anonymous function as its second argument. Notice the async
and await
keywords in the example below.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
it("Test Authentication", async function () {
await allure.step("Step 1", async function () {
await allure.step("Sub-step 1", async function () {
// ...
});
await allure.step("Sub-step 2", async function () {
// ...
});
});
await allure.step("Step 2", async function () {
// ...
});
});
});
Parametrized tests
allure.parameter(name: string, value: any, options?: ParameterOptions): Promise<void>
Specify a name
and value
of a parameter that was used during this test. See Parametrized tests for more details.
The options
argument, if given, must be an object with two optional properties excluded
and mode
.
If
excluded
is set to true, Allure will not use the parameter when comparing the current test result with previous one in the history. This argument is only used by Allure TestOps.The
mode
affects how the parameter will be displayed in the report. Available options are:"default"
(same as not specifying any mode) — the parameter and its value will be shown in a table along with other parameters."masked"
— the parameter will be shown in the table, but its value will be hidden. Use this mode for passwords, tokens and other sensitive parameters."hidden"
— the parameter and its value will not be shown in the test report. Note, however, that it is still possible to extract the value from theallure_results
directory if you publish it.
TypeScriptimport { allure } from "./helpers/setup";
describe("Test My Website", function () {
for (const login of ["johndoe", "[email protected]"]) {
it(`Test Authentication as ${login}`, async function () {
allure.parameter("login", login);
allure.parameter("time", new Date().toUTCString(), { excluded: true });
// ...
});
}
});
Attachments
attachment(name: string, content: Buffer | string, options: ContentType | string | AttachmentOptions): Promise<void>
Add an attachment under the given name
to the test result.
The content
can be a text string or a base64-encoded Buffer
. You can use data produced by any function, not necessarily read from an actual file.
The options
argument controls the MIME type of the content and the filename extension that will be used if a user downloads the attachment from the test report. You can either specify both options in an object (as shown for the image attachment below) or just specify the MIME type to let Allure deduce the appropriate filename extension automatically (as shown for the text attachment below). In either case, the MIME type can be a value from the ContentType
enumeration or any string.
TypeScriptimport { allure } from "./helpers/setup";
import { ContentType } from "allure-js-commons";
import * as fs from "fs";
describe("Test My Website", function () {
it("Test Authentication", async function () {
// ...
await allure.attachment("Text file", "This is the file content.", ContentType.TEXT);
await allure.attachment("Screenshot", fs.readFileSync("/path/to/image.png"), {
contentType: ContentType.PNG,
fileExtension: "png",
});
});
});