Skip to content

Commit

Permalink
add pending and unknown test status
Browse files Browse the repository at this point in the history
  • Loading branch information
Dileep17 committed Feb 14, 2023
1 parent 045aa26 commit f37d310
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 49 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Sample implementation can be found in `test/demo/demo.spec.js` and `test/demo/b
#### setTestInfo
For mapping test information to data collected, server binding `POST: /session/:sessionId/setTestInfo` is exposed. This binding accepts JSON payload with keys as mentioned below

| key | Description | Type | Accepted Values |
| ----------- | ----------- | ---- | --------------- |
| testName | Name of the test | Mandatory | any string |
| testStatus | Test execution status | Mandatory | PASSED, FAILED |
| error | Reason for test Failure | Optinal | any string |
| key | Description | Type | Accepted Values |
| ----------- | ----------- | ---- | --------------- |
| testName | Name of the test | Mandatory | any string |
| testStatus | Test execution status | Mandatory | PASSED, FAILED, PENDING, All other string considered as unknown |
| error | Reason for test Failure | Optinal | any string |

ex:
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-reporter-plugin",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.13",
"description": "Appium 2.0 plugin for generating html report with screenshots server side.",
"main": "./lib/index.js",
"scripts": {
Expand Down Expand Up @@ -32,7 +32,6 @@
},
"homepage": "https://github.com/AppiumTestDistribution/appium-reporter-plugin#readme",
"dependencies": {
"babel-cli": "^6.26.0",
"edit-json-file": "^1.7.0",
"fs-extra": "^11.1.0",
"jpeg-js": "^0.4.4",
Expand All @@ -52,6 +51,7 @@
"mainClass": "ReportPlugin"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"@babel/core": "^7.18.6",
"@babel/node": "^7.18.6",
"@typescript-eslint/parser": "^5.38.1",
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export const cmdExclusionList = [
'closeapp',
'background',
];
export const testStatusValues = ['PASSED', 'FAILED'];
export const testStatusValues = ['PASSED', 'FAILED', 'PENDING'];
2 changes: 1 addition & 1 deletion src/reportTemplate/bundle.js

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const editJsonFile = require('edit-json-file');
import { parse } from 'node-html-parser';
const { v4: uuidv4 } = require('uuid');
import log from './logger.js';
import { htmlTemplatePath, jsonReportPath, bundlePath, testStatusValues, reportPath } from './constants';
import { htmlTemplatePath, jsonReportPath, bundlePath, reportPath } from './constants';

async function getSessionFilePath(sessionId){
return `${reportPath}/${sessionId}.json`;
Expand All @@ -27,21 +27,28 @@ async function initReport(sessionId, deviceDetails) {
}
}

async function getTestStatus(status){
status = status.toUpperCase();
if(['PASS', 'PASSED'].includes(status))
return 'PASSED';
else if(['FAIL', 'FAILED'].includes(status))
return 'FAILED';
else if(['PENDING', 'WIP'].includes(status))
return 'PENDING';
else
return 'UNKNOWN';
}

async function setTestInfo(sessionId, testName, testStatus, error = undefined) {
if (sessionId === undefined || testName === undefined || testStatus === undefined)
throw new Error('sessionId, testName, testStatus are mandatory arguments');

let file = await editJsonFile(jsonReportPath);

if (!testStatusValues.includes(testStatus.toUpperCase()))
throw new Error(`Test status ${testStatus} is not valid state.`);

const info = {};
info['testName'] = testName;
info['testStatus'] = testStatus.toUpperCase();
info['testStatus'] = await getTestStatus(testStatus);
if (error)
info['error'] = error;
// info['error'] = Buffer.from(error, 'utf8').toString('base64');
info['sessionId'] = sessionId;
await file.append('tests', info);
await file.save();
Expand Down
10 changes: 5 additions & 5 deletions src/web/components/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React from 'react';
import ChartJS from 'chart.js/auto';
import { Doughnut } from 'react-chartjs-2';

export const Canvas = ({ passCount, failCount }) => {
const labels = ['PASSED', 'FAILED'];

export const Canvas = ({ passCount, failCount, pendingCount, unknownCount }) => {
const labels = ['PASSED', 'FAILED', 'PENDING', 'UNKNOWN'];
console.log(`Canvas passcount = ${passCount}; failCount = ${failCount}; pendingCount = ${pendingCount}; unknownCount = ${unknownCount}`);
const chartData = {
labels: labels,
datasets: [
{
label: 'Test Execution Result',
data: [passCount, failCount],
backgroundColor: ['rgb(46,139,87)', 'rgb(255, 99, 132)'],
data: [passCount, failCount, pendingCount, unknownCount],
backgroundColor: ['rgb(46,139,87)', 'rgb(255, 99, 132)', 'rgb(51, 175, 255)', 'rgb(253, 218, 13)'],
},
],
};
Expand Down
7 changes: 6 additions & 1 deletion src/web/components/OverallExecutionSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@ export const OverAllExecutionSummary = (props) => {
const results = props.data.testInfo;
let passCount = 0;
let failCount = 0;
let pendingCount = 0;
let unknownCount = 0;
let resultElements = [];

const tests = props.data.tests;
for(const test of tests) {
console.log(`test = ${test.testName}; status = ${status}`);
const name = test.testName;
const status = test.testStatus;
if (status === 'PASSED') {
passCount = passCount + 1;
} else if (status === 'FAILED') {
failCount = failCount + 1;
} else if (status === 'PENDING') {
pendingCount = pendingCount + 1;
} else {
unknownCount = unknownCount + 1;
}
const deviceDetails = props.data.sessions[test.sessionId];
resultElements = resultElements.concat({ name, status, ...deviceDetails });
}
console.log(`passcount = ${passCount}; failCount = ${failCount}; pendingCount = ${pendingCount}; unknownCount = ${unknownCount}`);

return (
<div className="overall-execution-summary-data">
<h5 className="test-summary-header summary-text-heading">Overall Execution Summary</h5>
<div className="chart-box">
<span>Execution Status Breakup</span>
<Canvas passCount={passCount} failCount={failCount} />
<Canvas passCount={passCount} failCount={failCount} pendingCount={pendingCount} unknownCount={unknownCount}/>
</div>
<table className="table" rules="groups">
<thead className="table-header">
Expand Down
27 changes: 0 additions & 27 deletions test/unit/repoter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,6 @@ describe('Record data in JSON file', function () {
});
});

it('Should throw error when invalid testStatus is passed', async function () {
await Reporter.initReport(sessionId);
const testStatus = 'passed';
await Reporter.setTestInfo(sessionId, 'Sample Test', testStatus);
const file = await editJsonFile(`${reportPath}/report.json`);
const fileContents = await file.toObject();
expect(fileContents).to.deep.equal(
{
'tests': [
{
testName: 'Sample Test',
testStatus: 'PASSED',
sessionId: sessionId
}
]
}
);
});

it('Should throw error when invalid testStatus is passed', async function () {
await Reporter.initReport('test');
const testStatus = 'invalid';
await expect(Reporter.setTestInfo('test', 'Sample test name', testStatus)).to.be.rejectedWith(
`Test status ${testStatus} is not valid state.`
);
});

it('Should throw error when sessionId is not provided', async function () {
await Reporter.initReport('test');
await expect(Reporter.setTestInfo()).to.be.rejectedWith(
Expand Down

0 comments on commit f37d310

Please sign in to comment.