Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to access testrail behind a proxy #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Add reporter to your `cypress.json`:
"password": "password",
"projectId": 1,
"suiteId": 1,
"proxy": "http://some-proxy:8080"
}
```

Expand Down Expand Up @@ -84,6 +85,9 @@ A comma-separated list of references/requirements — requires TestRail 6.1 or l

**filter**: _string_ (optional: needs "includeAllInTestRun": false) Only return cases with matching filter string in the case title

**proxy**: _string_ proxy to be used to access testrail. When you set `CYPRESS_TESTRAIL_REPORTER_PROXY` in
environment variables, this option would be overwritten with it.

## Multiple suite

This reporter can handle multiple suite project in TestRail. In order to use it, don't define **suiteId** under **cypress.json** file and instead you should pass **testRailSuiteId** variable when you define all other CLI agruments for cypress execution(through command line). If you are using CI integration solution (e.g. GitLab) **testRailSuiteId** can be set before every pipeline job or predefined for each spec (test) file for which suiteId belongs to.
Expand Down
4 changes: 4 additions & 0 deletions src/lib/cypress-testrail-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class CypressTestRailReporter extends reporters.Spec {
this.reporterOptions.refs = process.env.CYPRESS_TESTRAIL_REPORTER_REFS;
}

if (process.env.CYPRESS_TESTRAIL_REPORTER_PROXY) {
this.reporterOptions.proxy = process.env.CYPRESS_TESTRAIL_REPORTER_PROXY;
}

this.testRailApi = new TestRail(this.reporterOptions);
this.testRailValidation = new TestRailValidation(this.reporterOptions);

Expand Down
1 change: 1 addition & 0 deletions src/lib/testrail.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface TestRailOptions {
groupId?: number;
filter?: string;
typeId?: number;
proxy?: string;
}

export enum Status {
Expand Down
12 changes: 12 additions & 0 deletions src/lib/testrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ export class TestRail {
private includeAll: Boolean = true;
private caseIds: Number[] = [];
private retries: number;
private proxy: { host: string, port: string, protocol: string };

constructor(private options: TestRailOptions) {
this.base = `${options.host}/index.php?/api/v2`;
this.runId;

if (this.options.proxy) {
const proxyUrl = new URL(this.options.proxy)
this.proxy = { protocol: proxyUrl.protocol, host: proxyUrl.hostname, port: proxyUrl.port }
}
}

/**
Expand Down Expand Up @@ -49,6 +55,7 @@ export class TestRail {
axios({
method:'get',
url: url,
proxy: this.proxy,
headers: { 'Content-Type': 'application/json' },
auth: {
username: this.options.username,
Expand All @@ -71,6 +78,7 @@ export class TestRail {
axios({
method: 'post',
url: `${this.base}/add_run/${this.options.projectId}`,
proxy: this.proxy,
headers: { 'Content-Type': 'application/json' },
auth: {
username: this.options.username,
Expand Down Expand Up @@ -100,6 +108,7 @@ export class TestRail {
axios({
method: 'post',
url: `${this.base}/delete_run/${this.runId}`,
proxy: this.proxy,
headers: { 'Content-Type': 'application/json' },
auth: {
username: this.options.username,
Expand All @@ -115,6 +124,7 @@ export class TestRail {
axios({
method: 'post',
url: `${this.base}/add_results_for_cases/${this.runId}`,
proxy: this.proxy,
headers: { 'Content-Type': 'application/json' },
auth: {
username: this.options.username,
Expand All @@ -137,6 +147,7 @@ export class TestRail {
axios({
method: 'post',
url: `${this.base}/add_attachment_to_result/${resultId}`,
proxy: this.proxy,
headers: { ...form.getHeaders() },
auth: {
username: this.options.username,
Expand Down Expand Up @@ -174,6 +185,7 @@ export class TestRail {
axios({
method: 'post',
url: `${this.base}/close_run/${this.runId}`,
proxy: this.proxy,
headers: { 'Content-Type': 'application/json' },
auth: {
username: this.options.username,
Expand Down