Updated script to only take screenshots on failed steps
This commit is contained in:
@@ -2791,31 +2791,31 @@ const takeScreenshot = async (driver, stepIndex, stepDescription) => {
|
||||
};
|
||||
|
||||
const clearOldResults = () => {
|
||||
// Remove old screenshots
|
||||
//Remove old screenshots
|
||||
const screenshotDir = path.join('screenshots', 'frameworkFrameworkGroupsDIV');
|
||||
if (fs.existsSync(screenshotDir)) {
|
||||
fs.rmSync(screenshotDir, { recursive: true, force: true });
|
||||
}
|
||||
fs.mkdirSync(screenshotDir, { recursive: true });
|
||||
|
||||
// Remove old Excel file
|
||||
//Remove old Excel file
|
||||
if (fs.existsSync('frameworkFrameworkGroupsDIVResults.xlsx')) {
|
||||
fs.unlinkSync('frameworkFrameworkGroupsDIVResults.xlsx');
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
// Initialize workbook and worksheet
|
||||
//Initialize workbook and worksheet
|
||||
clearOldResults();
|
||||
|
||||
// Initialize workbook and worksheet
|
||||
//Initialize workbook and worksheet
|
||||
workbook = XLSX.utils.book_new();
|
||||
worksheet = XLSX.utils.aoa_to_sheet([
|
||||
['Step Number', 'Step Description', 'Status', 'Timestamp', 'Screenshot']
|
||||
]);
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
||||
|
||||
// Log test start time
|
||||
//Log test start time
|
||||
worksheet = logStep(worksheet, 'Test Start', 'Started', '', startTime, '');
|
||||
|
||||
let allStepsPassed = true;
|
||||
@@ -2824,13 +2824,37 @@ try {
|
||||
const stepIndex = steps.indexOf(step) + 1;
|
||||
const timestamp = new Date().toISOString();
|
||||
|
||||
try {
|
||||
await step.action();
|
||||
const screenshotPath = await takeScreenshot(driver, stepIndex, step.description);
|
||||
worksheet = logStep(worksheet, step.description, 'Passed', stepIndex, timestamp, screenshotPath);
|
||||
try {
|
||||
//Screenshot of failed step
|
||||
await step.action();
|
||||
|
||||
//Log a successful step with no screenshot
|
||||
worksheet = logStep(
|
||||
worksheet,
|
||||
step.description,
|
||||
'Passed',
|
||||
stepIndex,
|
||||
timestamp,
|
||||
null //No screenshot for passed steps
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
const screenshotPath = await takeScreenshot(driver, stepIndex, `${step.description}_Failed`);
|
||||
worksheet = logStep(worksheet, step.description, 'Failed', stepIndex, timestamp, screenshotPath);
|
||||
//Only take screenshot if the step fails
|
||||
const screenshotPath = await takeScreenshot(
|
||||
driver,
|
||||
stepIndex,
|
||||
`${step.description}_Failed`
|
||||
);
|
||||
|
||||
worksheet = logStep(
|
||||
worksheet,
|
||||
step.description,
|
||||
'Failed',
|
||||
stepIndex,
|
||||
timestamp,
|
||||
screenshotPath
|
||||
);
|
||||
|
||||
console.error(`Step ${stepIndex} FAILED: ${error.message}`);
|
||||
testStatus = 'Failed';
|
||||
allStepsPassed = false;
|
||||
@@ -2848,11 +2872,11 @@ try {
|
||||
testStatus = 'Failed';
|
||||
}
|
||||
|
||||
// Log test end time
|
||||
//Log test end time
|
||||
const endTime = new Date().toISOString();
|
||||
worksheet = logStep(worksheet, 'Test End', testStatus, '', endTime, '');
|
||||
|
||||
// Write the updated worksheet back to the workbook and save it
|
||||
//Write the updated worksheet back to the workbook and save it
|
||||
workbook.Sheets['Sheet1'] = worksheet;
|
||||
XLSX.writeFile(workbook, 'frameworkFrameworkGroupsDIVResults.xlsx');
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user