How to import Test Cases [PLUS]


Basic flow

  1. Get QAlity API Token & learn about our authentication: Rest API [PLUS] | General information

  2. Make a request: POST /api/import-test-cases

    1. remember that the request headers must include:

      • Authorization: Bearer <QAlity API Token>

      • Accept: application/json

    2. Request body data model:

    3. type ImportData = {
        projectId: number | string;
        testCases: Array<TestCase>;
      };
      
      type TestCase = {
        name: string;
        testSteps: Array<TestStep>;
        [additionalField: string]?: {}; // eg. description, priority
      };
      
      type TestStep = {
        step: string;
        data: string;
        result: string;
      };
      


      • Request response data model:

      type ImportResult = {
        success: Array<{
          testCaseKey: string;
          name: string;
        }>;
        errors: Array<{
          name: string;
          details: {
            errorMessages: Array<string>;
            errors: Record<FieldName, string>;
          };
        }>;
      };
      

Script

Example script is written in Deno.


.env

qality_api_token=<Your QAlity API Token>
project_id=<Project ID>


index.ts

TypeScript
/**
 * Run command:
 * $ deno run --allow-read --allow-net index.ts
 */

import { load } from "https://deno.land/std@0.204.0/dotenv/mod.ts";

/**
 * MODELS
 */

type ImportData = {
  projectId: number | string;
  testCases: Array<TestCase>;
};

type TestCase = {
  name: string;
  testSteps: Array<TestStep>;
  [additionalField: string]: {}; // eg. description, priority
};

type TestStep = {
  step: string;
  data: string;
  result: string;
};

/**
 * SETUP
 */

const env = await load();

const PROJECT_ID = env["project_id"];

const API_TOKEN = env["qality_api_token"];

const IMPORT_URL = `https://apps-qalityplus.soldevelo.com/api/testCases/import`;

const MockTestCases: ImportData = {
  projectId: PROJECT_ID,
  testCases: [
    {
      testSteps: [
        {
          step: "Enter sample page",
          data: "www.example.com",
          result: "The sample page shows up",
        },
        {
          step: "Click on the “log-in” button",
          data: "",
          result: "The log-in form is shown",
        },
        {
          step: "Enter username and password",
          data: "user: admin, password: password",
          result: "The username is visible and the password is masked",
        },
        {
          step: "Click enter",
          data: "",
          result: "The user is logged in and redirected to the home page",
        },
      ],
      name: "Test Case import demo 123",
    },
    {
      testSteps: [
        {
          step: "Enter sample page",
          data: "www.example.com",
          result: "The sample page shows up",
        },
        {
          step: "Click on the “log-out” button",
          data: "",
          result: "The user is redirected to log-in page",
        },
      ],
      name: "Test Case import demo 1234",
    },
  ],
};

/**
 * FUNCTIONS
 */

const postTestCases = async () => {
  const importResponse = await fetch(IMPORT_URL, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${API_TOKEN}`,
    },
    body: JSON.stringify(MockTestCases),
  });
  console.log("Result ok?", importResponse.ok);
};

await postTestCases();