Skip to content

Commit

Permalink
generate unique Id and use it to differentiate tests instead of sessi…
Browse files Browse the repository at this point in the history
…onId
  • Loading branch information
Dileep17 committed Jul 28, 2023
1 parent 5be5053 commit d01f7dc
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 76 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pids
*.pid
*.seed
*.pid.lock
*.class

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
Expand Down
552 changes: 508 additions & 44 deletions package-lock.json

Large diffs are not rendered by default.

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.1.0-beta.01",
"version": "1.1.0-beta.02",
"description": "Appium 2.0 plugin for generating html report with screenshots server side.",
"main": "./lib/index.js",
"scripts": {
Expand All @@ -25,7 +25,7 @@
"report",
"screenshot"
],
"author": "",
"author": "Dileep Bellamkonda <[email protected]>",
"license": "ISC",
"bugs": {
"url": "https://github.com/AppiumTestDistribution/appium-reporter-plugin/issues"
Expand Down
2 changes: 1 addition & 1 deletion src/reportTemplate/bundle.js

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ async function getTestStatus(status){
}

async function setTestInfo(sessionId, testName, testStatus, error = undefined) {
if (sessionId === undefined || sessionId === null)
const tid = await uuidv4();

if( sessionId !== undefined && sessionId !== null && sessionId !== 'null') {
const oldFileName = await getSessionFilePath(sessionId);
const newFileName = await getSessionFilePath(tid);
await fs.renameSync(oldFileName, newFileName);
} else if (sessionId === undefined || sessionId === null) {
sessionId = await uuidv4();
}

let file = await editJsonFile(jsonReportPath);
const info = {};
Expand All @@ -50,8 +57,10 @@ async function setTestInfo(sessionId, testName, testStatus, error = undefined) {
if (error)
info['error'] = error;
info['sessionId'] = sessionId;
info['testId'] = tid;
await file.append('tests', info);
await file.save();

}

async function setCmdData(sessionId, key, value, args) {
Expand All @@ -68,12 +77,13 @@ async function buildReport() {
let file = await editJsonFile(jsonReportPath);
let allData = await file.toObject();
allData.sessions = {};
const sessions = allData.tests.map(y => y.sessionId);
for(const session of sessions) {
const sessionFilePath = `${reportPath}/${session}.json`;
const testIds = allData.tests.map(y => [y.testId, y.sessionId]);
for(let i = 0; i < testIds.length; i++){
const testId = testIds[i][0];
const sessionFilePath = `${reportPath}/${testId}.json`;
const sessionData = await editJsonFile(sessionFilePath);
allData.sessions[session] = sessionData.toObject();
}
allData.sessions[testId] = sessionData.toObject();
}

const htmlTemplate = await fs.readFileSync(htmlTemplatePath, 'utf8');
let dom = await parse(htmlTemplate);
Expand Down
5 changes: 3 additions & 2 deletions src/web/components/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import React, { useEffect } from 'react';

export const Command = (props) => {
let data = props.data;
let sessionId = props.sessionId;
let testId = props.testId;
let cmd0 = props.cmd0;
let cmd1 = props.cmd1;

let dataId = cmd0 + cmd1;
let commandData = data.sessions[sessionId].data[dataId];
let commandData = data.sessions[testId].data[dataId];

let args = commandData['args'];
let execTime = args['execution time'];
let request = args['request'];
let response = args['response'];
let error = args['error']
let sessionId = args['sessionId']

return (
<div>
Expand Down
27 changes: 14 additions & 13 deletions src/web/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { Test } from './Test';

export const Navbar = (props) => {
let data = props.data.data;
let sessions = data.tests.map(test => test.sessionId);
const [filteredSessions, setFilteredSessions] = useState(sessions);
let tests = data.tests.map(test => test.testId);
const [filteredTests, setFilteredTests] = useState(tests);
const [showSummary, setShowSummary] = useState(true);
const [selectTest, setSelectTest] = useState(null);
const [showTestSummary, setShowTestSummary] = useState(true);

const filter = (e) => {
const value = e.target.value;
if (value == 0) {
setFilteredSessions(sessions);
setFilteredTests(tests);
return;
}

let newFilteredSessions = [];
let newFilteredTests = [];
let filterCondition = 'PASSED';
if (value == 2) {
filterCondition = 'FAILED';
Expand All @@ -28,18 +28,18 @@ export const Navbar = (props) => {
data.tests.map((test, key) => {
const testStatus =test.testStatus;
if(testStatus === filterCondition) {
newFilteredSessions.push(test.sessionId);
newFilteredTests.push(test.testId);
}
});
setFilteredSessions(newFilteredSessions);
setFilteredTests(newFilteredTests);
};

const SessionTab = ({ sessionId, testName, testStatus }) => {
const SessionTab = ({testName, testStatus, testId, sessionId}) => {
return (
<li
className={
!showSummary
? selectTest == sessionId
? selectTest == testId
? 'sidebar-link active'
: 'sidebar-link'
: 'sidebar-link'
Expand All @@ -51,7 +51,7 @@ export const Navbar = (props) => {
onClick={() => {
setShowSummary(false);
setShowTestSummary(true);
setSelectTest(sessionId);
setSelectTest(testId);
}}
>
{testName}
Expand Down Expand Up @@ -96,13 +96,14 @@ export const Navbar = (props) => {
</select>
</h6>
<ul className="sidebar-links" id="testLinks">
{filteredSessions.map((sessionId, key) => {
const test = data.tests.filter(test => test.sessionId === sessionId)[0];
{filteredTests.map((testId, key) => {
const test = data.tests.filter(test => test.testId === testId)[0];
const testName = test.testName;
const testStatus = test.testStatus;
const sessionId = test.sessionId;
return (
<div key={key}>
<SessionTab testName={testName} testStatus={testStatus} sessionId={sessionId} />
<SessionTab testName={testName} testStatus={testStatus} testId={testId} sessionId={sessionId} />
</div>
);
})}
Expand All @@ -111,7 +112,7 @@ export const Navbar = (props) => {
{!showSummary && (
<Test
data={data}
sessionId={selectTest}
testId={selectTest}
showTestSummary={showTestSummary}
setShowTestSummary={setShowTestSummary}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/web/components/OverallExecutionSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const OverAllExecutionSummary = (props) => {
} else {
unknownCount = unknownCount + 1;
}
const testDetails = props.data.sessions[test.sessionId];
const testDetails = props.data.sessions[test.testId];
const deviceDetails = 'deviceInfo' in testDetails ? testDetails.deviceInfo : undefined;
resultElements = resultElements.concat({ name, status, ...deviceDetails });
}
Expand Down
9 changes: 5 additions & 4 deletions src/web/components/Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { TestStatus } from './TestStatus';
import { Command } from './Command';

export const Test = (props) => {
let sessionId = props.sessionId;
let testId = props.testId;
// let sessionId = props.sessionId;
let data = props.data;
let session = data.sessions[sessionId];
let session = data.sessions[testId];
let showTestSummary = props.showTestSummary;
let setShowTestSummary = props.setShowTestSummary;

Expand Down Expand Up @@ -72,11 +73,11 @@ export const Test = (props) => {
}
</ul>
</nav>
{showTestSummary && <TestStatus data={data} sessionId={sessionId} />}
{showTestSummary && <TestStatus data={data} testId={testId}/>}
{!showTestSummary && selectedCommand0 && selectedCommand1 && (
<Command
data={props.data}
sessionId={props.sessionId}
testId={testId}
cmd0={selectedCommand0}
cmd1={selectedCommand1}
/>
Expand Down
7 changes: 4 additions & 3 deletions src/web/components/TestStatus.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';

export const TestStatus = (props) => {
const sessionId = props.sessionId;
const testId = props.testId;
// const sessionId = props.sessionId;
const data = props.data;
const test = data.tests.filter(test => test.sessionId === sessionId)[0];
const test = data.tests.filter(test => test.testId === testId)[0];
const testName = test.testName;
const testStatus = test.testStatus;
const error = test.error;
const testInfo = data.sessions[sessionId]
const testInfo = data.sessions[testId]

let platformName, platformVersion, deviceManufacturer, deviceModel, deviceApiLevel, deviceName;
try {
Expand Down

0 comments on commit d01f7dc

Please sign in to comment.