Syntax
Tip: Click the eyeball icon () in code blocks to toggle the visibility of the hidden lines.
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 fixture
and test
functions to make the Suite and Test case titles while publishing results.
Import Statement
Add the following statement at the beginning of your spec file, before any tests.
const { qase } = require("jest-qase-reporter/jest");
Now, let’s take a closer look at each of the Qase functions.
Qase ID
To associate an ID to your Test Case use qase.id
function. This function accepts a single integer representing the test’s ID in Qase.
Only one Qase Id can be linked to a test.
test(qase(1, "A test with Qase Id"), () => {
// 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()
.
describe("Example: title.test.js", () => {
test("Test without qase.title() method", () => {
// //test logic here
});
test("This won't appear in Qase", () => {
qase.title("This text will be the title of the test, in Qase");
// //test logic here
});
});
To update a Qase test case’s title from code, you must enable “Update test cases” in your project’s run settings.
If you don’t explicitly set a title using the qase.title
method, the title specified in the test
definition 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
definition
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.
describe("Example: steps.test.js", () => {
test("A Test case with steps, updated from test logic", async () => {
await qase.step("Initialize the environment", async () => {
// test logic here
});
await qase.step("Test Core Functionality of the app", async () => {
// test logic here
});
await qase.step("Verify Expected Behavior of the app", async () => {
// test logic here
});
await qase.step("Verify if user is able to log out successfully",async () => {
// 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.
describe("Example: suite.test.js", () => {
test("Test with a defined suite", () => {
qase.suite("This shall be a suite name");
//test logic here
});
test("Test within multiple levels of suite", () => {
qase.suite("Example: suite.test.js\tThis shall be a suite name\tChild Suite");
//test 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.
describe("Example: fields.test.js", () => {
test("Priority = low", async () => {
await qase.fields({ severity: "trivial", layer: "e2e", precondition: "example text" });
// //test logic here
});
});
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" },
];
describe("Example param.test.js\tSingle Parameter", () => {
testCases.forEach(({ browser }) => {
test(`Test login with ${browser}`, () => {
// qase.title("Verify if login page loads successfully");
qase.parameters({ Browser: browser });
// test logic here
});
});
});
describe("Example param.test.js\tGroup Parameter", () => {
testCases.forEach(({ username, password }) => {
test(`Test login with ${username} using qase.groupParameters`, () => {
// qase.title("Verify if user is able to login with their username.");
qase.groupParameters({
Username: username,
Password: password,
});
// test logic here
});
});
});
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.
describe("Example: comment.test.js", () => {
test("A test case with qase.comment()", () => {
qase.comment("Add a comment to the result");
// test logic here
});
});
Attach
Before using qase.attach
method. You need to set uploadAttachments":true
inside your qase.config.json
Configuration file.
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:
describe("Example: attach.test.js", () => {
test("Test result with attachment", async () => {
// To attach a single file
await qase.attach({
paths: "./attachments/test-file.txt",
});
// Add multiple attachments
await qase.attach({ paths: ['/path/to/file', '/path/to/another/file'] });
// Upload files contents directly from code
await 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 testcafe, its result will not be considered by the reporter.
describe("Example: ignore.test.js", () => {
test("This test is executed using Jest; however, it is NOT reported to Qase", () => {
qase.ignore();
// test logic here
});
});