https://www.npmjs.com/package/testrail-api-client
i am following this blog..
const client = require("testrail-api-client");
const client_options = require("testrail-api-client").default;
const options = {
domain: "example.testrail.com",
username: "[email protected]",
password: "ABC",
};
const client = new client_options(options);
Now i am converting this for TS..
I am planning to use environment variable . i have created .env file at the root project folder and TESTRAIL_DOMAIN/TESTRAIL_USERNAME.. etc
But when i run the suite it returns TESTRAIL_DOMAIN is undefined.. but when i create sample file index.js and if i print it is coming correctly.. when i run my playwright suite it return undefined.. I am sure that it is not reading.. How to make it read that variable?
Here is my customer reporter to update TestRail..
import { FullConfig, Suite,TestCase, TestResult,FullResult,TestError,TestStep } from "@playwright/test/reporter";
import { Reporter } from "@playwright/test/reporter";
import { DateTime } from 'luxon';
import client from 'testrail-api-client'
//import TestRailClient from 'testrail-api-client';
import * as fs from 'fs';
//const currentTestSteps: Map<string, string[]> = new Map();
let currentTests = new Map<string, string[]>();
export default class MyReporter implements Reporter {
onBegin(config: FullConfig, suite: Suite): void{
console.log("starting the run");
}
onTestBegin(test: TestCase, result: TestResult): void{
/*currentTestSteps.get(test.title)?.push(`================================================================`);
currentTestSteps.get(test.title)?.push(`TestCase Name: ${test.title}`);
currentTestSteps.get(test.title)?.push(`================================================================`);
console.log("Starting test " +test.title);
currentTestSteps.set(test.title, []);*/
currentTests.set(test.title, [] as string[]);
currentTests.get(test.title).push(`===============================================================================`);
currentTests.get(test.title).push(`TestCase Name: ${test.title}`);
currentTests.get(test.title).push(`===============================================================================`);
console.log("Starting test " + test.title);
}
onStepBegin(test: TestCase, result: TestResult, step: TestStep): void{
/*currentTestSteps.get(test.title)?.push(`Step Name: ${step.title}`);
console.log("Step Name: "+step.title);*/
currentTests.get(test.title)?.push(`Step Name: ${step.title}`);
console.log("Step Name: " + step.title);
}
onStepEnd(test: TestCase, result: TestResult, step: TestStep): void{
//console.log("Steps Results: "+ result.status);
}
onTestEnd(test: TestCase, result: TestResult): void{
console.log(result.status);
currentTests.get(test.title).push(`===============================================================================`);
currentTests.get(test.title).push(`TestCase Name: ${test.title} : ${result.status}`);
currentTests.get(test.title).push(`===============================================================================`);
const testStepsArray = currentTests.get(test.title);
if (testStepsArray && testStepsArray.length > 0) {
const fileDir = process.cwd() + '\resultDocumentDirectory\';
const now = DateTime.now().setZone('Etc/GMT');
const formattedDate = now.toFormat('MMddyyyyHHmmss');
const fileName = `${test.title}_${result.status}_Steps_${formattedDate}`;
fs.writeFileSync(`${fileDir}_${fileName}.txt`, testStepsArray.join('n'));
//currentTestSteps.delete(test.id);
}
console.log("Ending test " +test.title)
console.log("=================================================")
//R133311
let reportTests = [{ case_id: "47076995", status_id: 1, comment: "Test comment" }];
client.addResultsForCases("133311",reportTests).then(()=>{console.log("Done")}).catch((err)=> {console.log(err)});
}
}
AxiosError: getaddrinfo ENOTFOUND undefined
at Function.AxiosError.from (C:AMLnode_modulesaxioslibcoreAxiosError.js:89:14)
at RedirectableRequest.handleRequestError (C:AMLnode_modulesaxioslibadaptershttp.js:610:25)
at RedirectableRequest.emit (node:events:518:28)
at ClientRequest.eventHandlers.<computed> (C:AMLnode_modulesfollow-redirectsindex.js:38:24)
at ClientRequest.emit (node:events:518:28)
at TLSSocket.socketErrorListener (node:_http_client:500:9)
at TLSSocket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (C:AMLnode_modulesaxioslibcoreAxios.js:45:41)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
hostname: 'undefined',