Create and assign a test plan
This workflow creates a smoke test plan, adds three existing cases, waits for them to appear, and assigns the plan to the token owner.
Gather the IDs
Section titled “Gather the IDs”You need a project ID, a test plan folder ID, and repository case IDs from that project. Create or choose a test plan folder in TestCollab first, or use the folder methods.
Use a small, known case selection for your first run. The example verifies up to 100 cases; larger workflows should paginate that confirmation step.
Create, add, confirm and assign
Section titled “Create, add, confirm and assign”import { createConfiguration, TestPlansApi, TestPlanTestCasesApi, TestPlansAssignmentApi,} from '@testcollab/sdk';
const projectId = 123;const folderId = 456; // An existing test plan folder in this project.const caseIds = [101, 102, 103]; // Repository test case IDs.const config = createConfiguration(process.env.TESTCOLLAB_TOKEN!);
const plan = await new TestPlansApi(config).addTestPlan({ testPlanPayload: { title: 'Checkout smoke test', project: projectId, testPlanFolder: folderId, priority: 1, status: 1, },});
const planCases = new TestPlanTestCasesApi(config);await planCases.bulkAddTestPlanTestCases({ testPlanTestCaseBulkAddPayload: { testplan: plan.id, testCaseCollection: { testCases: caseIds, selector: [] }, },});
// Bulk work may be asynchronous. Confirm the cases exist before assigning them.let ready = false;for (let attempt = 0; attempt < 30; attempt++) { const rows = await planCases.getTestPlanTestCases({ project: projectId, testplan: plan.id, limit: 100 }); const addedIds = new Set(rows.map(row => row.testCase.id)); ready = caseIds.every(id => addedIds.has(id)); if (ready) break; await new Promise(resolve => setTimeout(resolve, 1000));}if (!ready) throw new Error('Cases are still being added. Check the plan before retrying.');
await new TestPlansAssignmentApi(config).assignTestPlan({ project: projectId, testplan: plan.id, testPlanAssignmentPayload: { executor: 'me', project: projectId, testplan: plan.id },});
console.log('Ready to execute:', plan.id);The initial bulk-add response can arrive before all cases have been added. The confirmation step reads the plan’s cases before moving on.
Assignment behavior
Section titled “Assignment behavior”executor: 'me' assigns work to the caller. For team assignment, use project member IDs and the assignment method.
Existing assignments and defaults are normally preserved. Only request an override when replacing those assignments is an intentional part of your workflow.
Execute and report
Section titled “Execute and report”The plan ID is not an execution ID. Read the plan’s run and execution records before recording results, or let the CLI reporting workflow map the result file for you.
For build traceability, supply the build ID on the plan when you create it. See builds and releases.