Updated code for login.js to fix the pass and fail status issue in excel file as well old results and screenshots will be removed now in every test execution

This commit is contained in:
AShahzad
2024-10-10 22:56:10 +05:00
parent 14d6e74fb1
commit e763e8ae45
3 changed files with 67 additions and 19 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -45,9 +45,12 @@ const expectedAuthenticationText = 'Authentication Failed. Please check the user
const expectedAuthenticationColor = 'rgba(231, 76, 60, 0.88)'; //orange const expectedAuthenticationColor = 'rgba(231, 76, 60, 0.88)'; //orange
const steps = [ const steps = [
{ description: 'Navigate to ExACT Landing Page', action: async () => await driver.navigate().to('https://stage.edgate.com/exact/login.php') }, { description: 'Navigate to ExACT Landing Page', action: async () => await driver.navigate().to('https://stage.edgate.com/exact/login.php') }, //PROD - https://correlation.edgate.com/exact/login.php
{ description: 'Expand browser', action: async () => await driver.manage().window().maximize() }, { description: 'Expand browser', action: async () => await driver.manage().window().maximize() },
//RIGHT PANEL
//ExACT logo
{ {
description: 'Verify ExACT logo is present', description: 'Verify ExACT logo is present',
action: async () => { action: async () => {
@@ -59,6 +62,7 @@ const steps = [
} }
}, },
//Welcome back text
{ {
description: 'Validate Welcome back text', description: 'Validate Welcome back text',
action: async () => { action: async () => {
@@ -70,6 +74,7 @@ const steps = [
} }
}, },
//Welcome back text color
{ {
description: 'Validate Welcome back text color', description: 'Validate Welcome back text color',
action: async () => { action: async () => {
@@ -81,6 +86,7 @@ const steps = [
} }
}, },
//Welcome back icon
{ {
description: 'Verify Welcome back icon is present', description: 'Verify Welcome back icon is present',
action: async () => { action: async () => {
@@ -92,6 +98,7 @@ const steps = [
} }
}, },
//Login title text
{ {
description: 'Validate Login title text', description: 'Validate Login title text',
action: async () => { action: async () => {
@@ -103,6 +110,7 @@ const steps = [
} }
}, },
//Login title text color
{ {
description: 'Validate Login title text color', description: 'Validate Login title text color',
action: async () => { action: async () => {
@@ -114,6 +122,7 @@ const steps = [
} }
}, },
//Login title text font
{ {
description: 'Validate Login title text font size', description: 'Validate Login title text font size',
action: async () => { action: async () => {
@@ -125,6 +134,7 @@ const steps = [
} }
}, },
//Username label text
{ {
description: 'Validate Username label text', description: 'Validate Username label text',
action: async () => { action: async () => {
@@ -136,6 +146,7 @@ const steps = [
} }
}, },
//Username label text color
{ {
description: 'Validate Username label text color', description: 'Validate Username label text color',
action: async () => { action: async () => {
@@ -147,6 +158,7 @@ const steps = [
} }
}, },
//Username textbox placeholder
{ {
description: 'Validate Username placeholder text', description: 'Validate Username placeholder text',
action: async () => { action: async () => {
@@ -158,6 +170,8 @@ const steps = [
} }
}, },
//Password label text
{ {
description: 'Validate Password label text', description: 'Validate Password label text',
action: async () => { action: async () => {
@@ -169,6 +183,7 @@ const steps = [
} }
}, },
//Password label text color
{ {
description: 'Validate Password label text color', description: 'Validate Password label text color',
action: async () => { action: async () => {
@@ -180,6 +195,7 @@ const steps = [
} }
}, },
//Password textbox placeholder
{ {
description: 'Validate Password placeholder text', description: 'Validate Password placeholder text',
action: async () => { action: async () => {
@@ -191,6 +207,7 @@ const steps = [
} }
}, },
//Forgot password text link color
{ {
description: 'Validate Forgot Password link text color', description: 'Validate Forgot Password link text color',
action: async () => { action: async () => {
@@ -202,6 +219,7 @@ const steps = [
} }
}, },
//Login button text
{ {
description: 'Validate Login button text', description: 'Validate Login button text',
action: async () => { action: async () => {
@@ -213,6 +231,7 @@ const steps = [
} }
}, },
//Login button background color
{ {
description: 'Validate Login button background color', description: 'Validate Login button background color',
action: async () => { action: async () => {
@@ -224,6 +243,7 @@ const steps = [
} }
}, },
//Don't have an account? text
{ {
description: 'Validate Dont have account text', description: 'Validate Dont have account text',
action: async () => { action: async () => {
@@ -235,6 +255,7 @@ const steps = [
} }
}, },
//Free trial button text
{ {
description: 'Validate Free trial button text', description: 'Validate Free trial button text',
action: async () => { action: async () => {
@@ -246,6 +267,7 @@ const steps = [
} }
}, },
//Free trial button background color
{ {
description: 'Validate Free trial button background color', description: 'Validate Free trial button background color',
action: async () => { action: async () => {
@@ -257,6 +279,7 @@ const steps = [
} }
}, },
//EdGate copyright image
{ {
description: 'Verify EdGate copyright image is present', description: 'Verify EdGate copyright image is present',
action: async () => { action: async () => {
@@ -268,12 +291,29 @@ const steps = [
} }
}, },
//Validation
{ description: 'Click Login button', action: async () => await driver.findElement(By.css('.login')).click() }, { description: 'Click Login button', action: async () => await driver.findElement(By.css('.login')).click() },
/*Username validation
{ description: 'Validate username validadtion text', action: async () =>
{ const elementText = await driver.findElement(By.css('?')).getText();
if (elementText === expectedUsernameValidationText)
{console.log('Passed: Username validation text matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedUsernameValidationText}"; Actual: "${elementText}"`);}
}
},*/
{ description: 'Enter username', action: async () => await driver.findElement(By.css('.form-control:nth-child(2)')).sendKeys('exact_juan') }, { description: 'Enter username', action: async () => await driver.findElement(By.css('.form-control:nth-child(2)')).sendKeys('exact_juan') },
{ description: 'Click Login button after entering username', action: async () => await driver.findElement(By.css('.login')).click() }, { description: 'Click Login button after entering username', action: async () => await driver.findElement(By.css('.login')).click() },
{ description: 'Enter incorrect password', action: async () => await driver.findElement(By.css('.passfield')).sendKeys('Edgate1') }, { description: 'Enter incorrect password', action: async () => await driver.findElement(By.css('.passfield')).sendKeys('Edgate1') },
{ description: 'Click Login button after entering wrong password', action: async () => await driver.findElement(By.css('.login')).click() }, { description: 'Click Login button after entering wrong password', action: async () => await driver.findElement(By.css('.login')).click() },
//Confirm validation message
{ {
description: 'Validate authentication failed validation text', description: 'Validate authentication failed validation text',
action: async () => { action: async () => {
@@ -285,6 +325,7 @@ const steps = [
} }
}, },
//Authentication validation text background color
{ {
description: 'Validate authentication alert background color', description: 'Validate authentication alert background color',
action: async () => { action: async () => {
@@ -312,30 +353,36 @@ const takeScreenshot = async (driver, stepIndex, stepDescription) => {
const screenshot = await driver.takeScreenshot(); const screenshot = await driver.takeScreenshot();
const dir = path.join('screenshots', 'loginScript'); const dir = path.join('screenshots', 'loginScript');
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
const screenshotFileName = `step_${stepIndex}_${stepDescription.replace(/\s+/g, '_')}.png`; const screenshotFileName = `step_${stepIndex}_${stepDescription.replace(/\s+/g, '_')}.png`;
const screenshotPath = path.join(dir, screenshotFileName); const screenshotPath = path.join(dir, screenshotFileName);
fs.writeFileSync(screenshotPath, screenshot, 'base64'); fs.writeFileSync(screenshotPath, screenshot, 'base64');
return screenshotPath; return screenshotPath;
}; };
const clearOldResults = () => {
// Remove old screenshots
const screenshotDir = path.join('screenshots', 'loginScript');
if (fs.existsSync(screenshotDir)) {
fs.rmSync(screenshotDir, { recursive: true, force: true });
}
fs.mkdirSync(screenshotDir, { recursive: true });
// Remove old Excel file
if (fs.existsSync('loginResults.xlsx')) {
fs.unlinkSync('loginResults.xlsx');
}
};
try { try {
// Initialize workbook and worksheet // Initialize workbook and worksheet
if (!fs.existsSync('loginResults.xlsx')) { clearOldResults();
// Initialize workbook and worksheet
workbook = XLSX.utils.book_new(); workbook = XLSX.utils.book_new();
worksheet = XLSX.utils.aoa_to_sheet([ worksheet = XLSX.utils.aoa_to_sheet([
['Step Number', 'Step Description', 'Status', 'Timestamp', 'Screenshot'] ['Step Number', 'Step Description', 'Status', 'Timestamp', 'Screenshot']
]); ]);
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1'); XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'loginResults.xlsx');
} else {
workbook = XLSX.readFile('loginResults.xlsx', { cellStyles: true });
const sheetName = workbook.SheetNames[0];
worksheet = workbook.Sheets[sheetName];
}
// Log test start time // Log test start time
worksheet = logStep(worksheet, 'Test Start', 'Started', '', startTime, ''); worksheet = logStep(worksheet, 'Test Start', 'Started', '', startTime, '');
@@ -355,6 +402,7 @@ try {
testStatus = 'Failed'; testStatus = 'Failed';
} }
} }
//Check if login was successful //Check if login was successful
const usernameValidation = await driver.wait(until.elementLocated(By.css('#navbarDropdown > span')), 5000).catch(() => false); const usernameValidation = await driver.wait(until.elementLocated(By.css('#navbarDropdown > span')), 5000).catch(() => false);