diff --git a/README.md b/README.md index 77911912..4f62767e 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ it("Can authenticate a valid userC123", ... **runName**: _string_ (optional) name of the Testrail run. +**includeAllInTestRun**: _bool_ (optional: default is true) will return all test cases in test run. set to false to return test runs based on filter or section/group. + +**groupId**: _string_ (optional: needs "includeAllInTestRun": false ) The ID of the section/group + +**filter**: _string_ (optional: needs "includeAllInTestRun": false) Only return cases with matching filter string in the case title + ## TestRail Settings To increase security, the TestRail team suggests using an API key instead of a password. You can see how to generate an API key [here](http://docs.gurock.com/testrail-api2/accessing#username_and_api_key). diff --git a/src/lib/testrail.interface.ts b/src/lib/testrail.interface.ts index 04a52f15..7ceeb2fa 100644 --- a/src/lib/testrail.interface.ts +++ b/src/lib/testrail.interface.ts @@ -5,6 +5,9 @@ export interface TestRailOptions { projectId: number; suiteId: number; assignedToId?: number; + includeAllInTestRun?: boolean; + groupId?: number; + filter?: string; } export enum Status { diff --git a/src/lib/testrail.ts b/src/lib/testrail.ts index c72cb248..a6dbdd89 100644 --- a/src/lib/testrail.ts +++ b/src/lib/testrail.ts @@ -5,12 +5,35 @@ import { TestRailOptions, TestRailResult } from './testrail.interface'; export class TestRail { private base: String; private runId: Number; + private includeALL: Boolean; + private caseNumbersArray: Number[]; constructor(private options: TestRailOptions) { this.base = `https://${options.domain}/index.php?/api/v2`; } - public createRun(name: string, description: string) { + public getCases () { + return axios({ + method:'get', + url: `${this.base}/get_cases/${this.options.projectId}&suite_id=${this.options.suiteId}§ion_id=${this.options.groupId}&filter=${this.options.filter}`, + headers: { 'Content-Type': 'application/json' }, + auth: { + username: this.options.username, + password: this.options.password + } + }) + .then(response => response.data.map(item =>item.id)) + .catch(error => console.error(error)); + } + + public async createRun (name: string, description: string) { + var slef = this; + slef.includeALL = true; + slef.caseNumbersArray = []; + if(this.options.includeAllInTestRun === false){ + slef.caseNumbersArray = await slef.getCases(); + slef.includeALL = false; + } axios({ method: 'post', url: `${this.base}/add_run/${this.options.projectId}`, @@ -23,7 +46,8 @@ export class TestRail { suite_id: this.options.suiteId, name, description, - include_all: true, + include_all: slef.includeALL, + case_ids: slef.caseNumbersArray }), }) .then(response => {