Syntax
Click here to view Example tests for the following syntax.
If you do not use any Qase syntax, the reporter uses the title from the describe
and test
functions to make the Suite and Test case titles while publishing results.
Example Spec file
describe("Demonstrates all Qase methods", () => {
qase(1, it("This is the test name", () => {
qase.title("This overrides the test name");
qase.suite("Suite name");
qase.fields({ priority: "high", severity: "critical" });
qase.attach({ paths: "./path/to/attachment.txt" });
qase.comment("This comment appears in the 'Actual Result' field.");
qase.ignore(); // doesn't report his result to Qase.
qase.parameters({ Browser: "Chromium" });
qase.groupParameters({ Username: "@alice", Password: "123" });
qase.step("Step 1: Open the site", () => // step logic );
// test logic
});
});
Import Statement
Add the following statement at the beginning of your spec file, before any tests.
import { qase } from "cypress-qase-reporter/mocha";
Now, let’s take a closer look at each of the Qase functions.
Qase Id
You can link multiple Qase Ids to a single test. Here’s an example:
qase(1, it("A single Qase Id", () => {
// Test logic here
..
qase([2,3,4], it("Link multiple Qase Ids", () => {
// Test logic here
..
Qase Title
The qase.title()
method is used to set the title of a test case, both when creating a new test case from the result, and when updating the title of an existing test case - if used with qase.id()
.
it("This won't appear in Qase", () => {
qase.title("This text will be the title of the test, in Qase");
// Test logic here
});
If you don’t explicitly set a title using the qase.title
method, the title specified in the test(..)
function will be used for new test cases. However, if the qase.title
method is defined, it always takes precedence and overrides the title from the test(..)
function.
Steps
The reporter uses the title from the qase.step
function as the step title. By providing clear and descriptive step names, you make it easier to understand the test’s flow when reviewing the test case.
Additionally, these steps get their own result in the Qase Test run, offering a well-organized summary of the test flow. This helps quickly identify the cause of any failures.
it("A Test case with steps, updated from code", () => {
qase.step("Step 1: Open the site: qase.io", () => {
// Step logic here
});
qase.step("Step 2: Click the 'Login' button", () => {
// Step logic here
});
qase.step("Step 3: Check if the page loads successfully", () => {
// Step logic here
});
});
Fields
Currently, you can define description
, pre & post conditions
, and fields like severity
, priority
, layer
with this method, allowing you to specify and maintain the context of the case, all directly from within your code.
it("Demonstrates all Qase methods", () => {
qase.fields({
priority: "high",
severity: "critical",
layer: "e2e",
description: "Example description",
preconditions: "Example precondition",
postconditions: "Example postcondition",
});
// Test logic here
});
Suite
You can use this method to nest the resulting test cases in a particular suite. There’s something to note here – suites, unlike test cases, are not identified uniquely by the Reporter.
Therefore, when defining an existing suite - the title of the suite is used for matching.
it("Test with a defined suite", () => {
qase.suite("Suite defined with qase.suite()");
/*
* Or, nest multiple levels of suites.
* `\t` is used for dividing each suite name.
*/
qase.suite("Suite defined with qase.suite()\tAuthentication\tLogin");
expect(true).to.equal(true);
});
Parameters
Parameters are a great way to make your tests more dynamic, reusable, and data-driven. By defining parameters in this method, you can ensure only one test case with all the parameters is created in your Qase project, avoiding duplication.
const testCases = [
{ browser: "Chromium", username: "@alice", password: "123" },
{ browser: "Firefox", username: "@bob", password: "456" },
{ browser: "Webkit", username: "@charlie", password: "789" },
];
testCases.forEach(({ browser }) => {
it(`Test login with ${browser}`, () => {
qase.title("Verify if page loads on all browsers");
qase.parameters({ Browser: browser }); // Single parameter
// test logic
testCases.forEach(({ username, password }) => {
it(`Test login with ${username} using qase.groupParameters`, () => {
qase.title("Verify if user is able to login with their username.");
qase.groupParameters({ // Group parameters
Username: username,
Password: password,
});
// test logic
Comment
In addition to test.step()
, this method can be used to provide any additional context to your test, it helps maintiain the code by clarifying the expected result of the test.
it("A test with qase.comment()", () => {
/*
* Please note, this comment is added to a Result, not to the Test case.
*/
qase.comment("This comment is added to the result");
// test logic here
});
Attach
This method can help attach one, or more files to the test’s result. You can also add the file’s contents, directly from code. For example:
it("Test result with attachment", async () => {
To attach a single file
qase.attach({
paths: "./cypress/e2e/tests/attachments/test-file.txt",
});
// Add multiple attachments.
qase.attach({ paths: ['/path/to/file', '/path/to/another/file'] });
// Upload file's contents directly from code.
qase.attach({ name: 'attachment.txt', content: 'Hello, world!', contentType: 'text/plain' });
// test logic here
});
Ignore
If this method is added, the reporter will exclude the test’s result from the report sent to Qase. While the test will still executed by Cypress, its result will not be considered by the reporter.
it("This test is executed by Cypress, however, it is NOT reported to Qase", () => {
qase.ignore();
// test logic here
});