Skip to content

Commit

Permalink
Merge pull request awaragi#6 from adodge1/addition-testrails-run-spec…
Browse files Browse the repository at this point in the history
…ific

feat: allow testRails run select test cases
  • Loading branch information
mickosav committed Jul 6, 2020
2 parents 2c45aa6 + b4cbdd3 commit cc643f0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions src/lib/testrail.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export interface TestRailOptions {
projectId: number;
suiteId: number;
assignedToId?: number;
includeAllInTestRun?: boolean;
groupId?: number;
filter?: string;
}

export enum Status {
Expand Down
28 changes: 26 additions & 2 deletions src/lib/testrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}&section_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}`,
Expand All @@ -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 => {
Expand Down

0 comments on commit cc643f0

Please sign in to comment.