From 8daf5cac8bbd0e003bd70eb3bcddb7966f1692d4 Mon Sep 17 00:00:00 2001 From: Michael Zanggl Date: Thu, 5 Jan 2023 14:36:21 +0900 Subject: [PATCH] add support for proxy --- README.md | 4 ++++ src/lib/cypress-testrail-reporter.ts | 4 ++++ src/lib/testrail.interface.ts | 1 + src/lib/testrail.ts | 12 ++++++++++++ 4 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 040cb42e..7bde6d2a 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Add reporter to your `cypress.json`: "password": "password", "projectId": 1, "suiteId": 1, + "proxy": "http://some-proxy:8080" } ``` @@ -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. diff --git a/src/lib/cypress-testrail-reporter.ts b/src/lib/cypress-testrail-reporter.ts index 55e3ea63..3c072089 100644 --- a/src/lib/cypress-testrail-reporter.ts +++ b/src/lib/cypress-testrail-reporter.ts @@ -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); diff --git a/src/lib/testrail.interface.ts b/src/lib/testrail.interface.ts index 6d278bc1..a80c9069 100644 --- a/src/lib/testrail.interface.ts +++ b/src/lib/testrail.interface.ts @@ -9,6 +9,7 @@ export interface TestRailOptions { groupId?: number; filter?: string; typeId?: number; + proxy?: string; } export enum Status { diff --git a/src/lib/testrail.ts b/src/lib/testrail.ts index f357be9b..0057f949 100644 --- a/src/lib/testrail.ts +++ b/src/lib/testrail.ts @@ -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 } + } } /** @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,