373 lines
16 KiB
JavaScript
373 lines
16 KiB
JavaScript
import { Builder, By, Key, until } from 'selenium-webdriver';
|
|
import fs from 'fs';
|
|
import XLSX from 'xlsx';
|
|
import path from 'path';
|
|
import { assert } from 'console';
|
|
|
|
const ExACT_login = (req, res) => {
|
|
res.send('<h2>ExACT Automated Test Script - Login: Initiated</h2>');
|
|
(async function example() {
|
|
let driver = await new Builder().forBrowser('chrome').build();
|
|
let testStatus = 'Failed';
|
|
let workbook;
|
|
let worksheet;
|
|
const startTime = new Date().toISOString();
|
|
|
|
//Right Panel:
|
|
//Welcome back
|
|
const expectedWelcomeBackText = 'WELCOME BACK!';
|
|
const expectedWelcomeBackColor = 'rgba(117, 117, 117, 1)' //gray
|
|
//Login
|
|
const expectedLoginTitleText = 'Login to your account';
|
|
const expectedLoginTitleColor = 'rgba(40, 39, 90, 1)'; //navy blue
|
|
const expectedLoginTitleFont = '32px';
|
|
//Username
|
|
const expectedUsernameLabel = 'Username';
|
|
const expectedUsernameColor = 'rgba(40, 39, 90, 1)'; //navy blue
|
|
const expectedUsernamePlaceholder = 'Username';
|
|
//Password
|
|
const expectedPasswordLabel = 'Password';
|
|
const expectedPasswordColor = 'rgba(40, 39, 90, 1)'; //navy blue
|
|
const expectedPasswordPlaceholder = 'Password';
|
|
//Forgot password link
|
|
const expectedForgotPasswordLinkColor = 'rgba(40, 39, 90, 1)'; //navy blue
|
|
//Login button
|
|
const expectedLoginButtonText = 'Login';
|
|
const expectedLoginButtonColor = 'rgba(48, 200, 172, 1)'; //teal
|
|
//Don't have account text
|
|
const expectedDontHaveAccountText = `DON'T HAVE AN ACCOUNT?`;
|
|
//Free trial button
|
|
const expectedFreeTrialButtonText = '30 Day';
|
|
const expectedFreeTrialButtonColor = 'rgba(0, 0, 0, 0)'; //white
|
|
|
|
//Validation
|
|
const expectedAuthenticationText = 'Authentication Failed. Please check the username and password you entered and try again.';
|
|
const expectedAuthenticationColor = 'rgba(231, 76, 60, 0.88)'; //orange
|
|
|
|
const steps = [
|
|
{ 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() },
|
|
|
|
//RIGHT PANEL
|
|
//ExACT logo
|
|
{ description: 'Verify ExACT logo is present', action: async () =>
|
|
{ const expectedExactLogo = await driver.wait(until.elementLocated(By.css('.logo')), 5000).catch(() => false);
|
|
if (expectedExactLogo)
|
|
{console.log('Passed: ExACT logo present');}
|
|
else
|
|
{console.log('FAILED: ExACT logo not found');}
|
|
}
|
|
},
|
|
|
|
//Welcome back text
|
|
{ description: 'Validate Welcome back text', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('#formLogin > p')).getText();
|
|
if (elementText === expectedWelcomeBackText)
|
|
{console.log('Passed: Welcome Back! text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedWelcomeBackText}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Welcome back text color
|
|
{ description: 'Validate Welcome back text color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('#formLogin > p')).getCssValue('color');
|
|
if (elementStyle === expectedWelcomeBackColor)
|
|
{console.log('Passed: Welcome back text color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Welcome back text color Expected: "${expectedWelcomeBackColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//Welcome back icon
|
|
{ description: 'Verify Welcome back icon is present', action: async () =>
|
|
{ const expectedWelcomeBackIcon = await driver.wait(until.elementLocated(By.css('p > img')), 5000).catch(() => false);
|
|
if (expectedWelcomeBackIcon)
|
|
{console.log('Passed: Welcome back icon present');}
|
|
else
|
|
{console.log('FAILED: Welcome back icon not found');}
|
|
}
|
|
},
|
|
|
|
//Login title text
|
|
{ description: 'Validate Login title text', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('h2:nth-child(3)')).getText();
|
|
if (elementText === expectedLoginTitleText)
|
|
{console.log('Passed: Login title text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedLoginTitleText}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Login title text color
|
|
{ description: 'Validate Login title text color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('h2:nth-child(3)')).getCssValue('color');
|
|
if (elementStyle === expectedLoginTitleColor)
|
|
{console.log('Passed: Login title text color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Login title text color Expected: "${expectedLoginTitleColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//Login title text font
|
|
{ description: 'Validate Login title text font size', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('h2:nth-child(3)')).getCssValue('font-size');
|
|
if (elementStyle === expectedLoginTitleFont)
|
|
{console.log('Passed: Login title text font-size matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Login title text font-size Expected: "${expectedLoginTitleFont}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//Username label text
|
|
{ description: 'Validate Username label text', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('.form-group:nth-child(4) > label')).getText();
|
|
if (elementText === expectedUsernameLabel)
|
|
{console.log('Passed: Username label text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedUsernameLabel}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Username label text color
|
|
{ description: 'Validate Username label text color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('.form-group:nth-child(4) > label')).getCssValue('color');
|
|
if (elementStyle === expectedUsernameColor)
|
|
{console.log('Passed: Username label text color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Username label text color Expected: "${expectedUsernameColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//Username textbox placeholder
|
|
{ description: 'Validate Username placeholder text', action: async () =>
|
|
{ const elementValue = await driver.findElement(By.css('.form-control:nth-child(2)')).getAttribute('placeholder');
|
|
if (elementValue === expectedUsernamePlaceholder)
|
|
{console.log('Passed: Username placeholder text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Username placeholder text Expected: "${expectedUsernamePlaceholder}"; Actual: "${elementValue}"`);}
|
|
}
|
|
},
|
|
|
|
//Password label text
|
|
{ description: 'Validate Password label text', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('.form-group:nth-child(5) > label')).getText();
|
|
if (elementText === expectedPasswordLabel)
|
|
{console.log('Passed: Password label text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedPasswordLabel}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Password label text color
|
|
{ description: 'Validate Password label text color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('.form-group:nth-child(5) > label')).getCssValue('color');
|
|
if (elementStyle === expectedPasswordColor)
|
|
{console.log('Passed: Password label text color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Password label text color Expected: "${expectedPasswordColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//Password textbox placeholder
|
|
{ description: 'Validate Password placeholder text', action: async () =>
|
|
{ const elementValue = await driver.findElement(By.css('.passfield')).getAttribute('placeholder');
|
|
if (elementValue === expectedPasswordPlaceholder)
|
|
{console.log('Passed: Password placeholder text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Password placeholder text Expected: "${expectedPasswordPlaceholder}"; Actual: "${elementValue}"`);}
|
|
}
|
|
},
|
|
|
|
//Forgot password text link color
|
|
{ description: 'Validate Forgot Password link text color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.linkText('Forgot Password?')).getCssValue('color');
|
|
if (elementStyle === expectedForgotPasswordLinkColor)
|
|
{console.log('Passed: Forgot password link text color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Forgot password link text color Expected: "${expectedForgotPasswordLinkColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//Login button text
|
|
{ description: 'Validate Login button text', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('.login')).getAttribute('value');
|
|
if (elementText === expectedLoginButtonText)
|
|
{console.log('Passed: Login button text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedLoginButtonText}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Login button background color
|
|
{ description: 'Validate Login button background color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('.login')).getCssValue('background-color');
|
|
if (elementStyle === expectedLoginButtonColor)
|
|
{console.log('Passed: Login button background color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Login button background color Expected: "${expectedLoginButtonColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//Don't have an account? text
|
|
{ description: 'Validate Dont have account text', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('p:nth-child(1)')).getText();
|
|
if (elementText === expectedDontHaveAccountText)
|
|
{console.log('Passed: Dont have an account text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedDontHaveAccountText}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Free trial button text
|
|
{ description: 'Validate Free trial button text', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('.btn > span')).getText();
|
|
if (elementText === expectedFreeTrialButtonText)
|
|
{console.log('Passed: Free trial button text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedFreeTrialButtonText}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Free trial button background color
|
|
{ description: 'Validate Free trial button background color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('.btn > span')).getCssValue('background-color');
|
|
if (elementStyle === expectedFreeTrialButtonColor)
|
|
{console.log('Passed: Free trial button background color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Free trial button background color Expected: "${expectedFreeTrialButtonColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
//EdGate copyright image
|
|
{ description: 'Verify EdGate copyright image is present', action: async () =>
|
|
{ const expectedEdGateCopyright = await driver.wait(until.elementLocated(By.css('.logincopyright > img')), 5000).catch(() => false);
|
|
if (expectedEdGateCopyright)
|
|
{console.log('Passed: EdGate copyright image present');}
|
|
else
|
|
{console.log('FAILED: EdGate copyright not found');}
|
|
}
|
|
},
|
|
|
|
//Validation
|
|
{ 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: '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: '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', action: async () =>
|
|
{ const elementText = await driver.findElement(By.css('.alert')).getText();
|
|
if (elementText === expectedAuthenticationText)
|
|
{console.log('Passed: Authentication text matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Expected: "${expectedAuthenticationText}"; Actual: "${elementText}"`);}
|
|
}
|
|
},
|
|
|
|
//Authentication validation text background color
|
|
{ description: 'Validate authentication alert background color', action: async () =>
|
|
{ const elementStyle = await driver.findElement(By.css('.alert')).getCssValue('background-color');
|
|
if (elementStyle === expectedAuthenticationColor)
|
|
{console.log('Passed: Authentication alert background color matched as expected');}
|
|
else
|
|
{console.log(`FAILED: Authentication alert background color Expected: "${expectedAuthenticationColor}"; Actual: "${elementStyle}"`);}
|
|
}
|
|
},
|
|
|
|
{ description: 'Enter username', action: async () => await driver.findElement(By.css('.form-control:nth-child(2)')).sendKeys('exact_juan') },
|
|
{ description: 'Enter correct password', action: async () => await driver.findElement(By.css('.passfield')).sendKeys('Edgate1!') },
|
|
{ description: 'Click Login button after entering correct password', action: async () => await driver.findElement(By.css('.login')).click() },
|
|
{ description: 'Wait for login process to complete', action: async () => await driver.sleep(10000) },
|
|
];
|
|
|
|
const logStep = (worksheet, stepDescription, status, stepIndex, timestamp, screenshotPath) => {
|
|
const json_data = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
|
json_data.push([stepIndex, stepDescription, status, timestamp, screenshotPath]);
|
|
return XLSX.utils.aoa_to_sheet(json_data);
|
|
};
|
|
|
|
const takeScreenshot = async (driver, stepIndex, stepDescription) => {
|
|
const screenshot = await driver.takeScreenshot();
|
|
|
|
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 screenshotPath = path.join(dir, screenshotFileName);
|
|
fs.writeFileSync(screenshotPath, screenshot, 'base64');
|
|
return screenshotPath;
|
|
};
|
|
|
|
try {
|
|
// Initialize workbook and worksheet
|
|
if (!fs.existsSync('loginResults.xlsx')) {
|
|
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');
|
|
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
|
|
worksheet = logStep(worksheet, 'Test Start', 'Started', '', startTime, '');
|
|
|
|
for (const step of steps) {
|
|
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);
|
|
} catch (error) {
|
|
const screenshotPath = await takeScreenshot(driver, stepIndex, `${step.description}_Failed`);
|
|
worksheet = logStep(worksheet, step.description, 'Failed', stepIndex, timestamp, screenshotPath);
|
|
throw error; // Re-throw the error to stop further execution if necessary
|
|
}
|
|
}
|
|
|
|
//Check if login was successful
|
|
const usernameValidation = await driver.wait(until.elementLocated(By.css('#navbarDropdown > span')), 5000).catch(() => false);
|
|
|
|
if (usernameValidation) {
|
|
console.log('PASSED: System logged in as expected');
|
|
testStatus = 'Passed';
|
|
} else {
|
|
console.log('FAILED: Unable to log in');
|
|
}
|
|
|
|
// Log test end time
|
|
const endTime = new Date().toISOString();
|
|
worksheet = logStep(worksheet, 'Test End', 'Ended', '', endTime, '');
|
|
|
|
// Write the updated worksheet back to the workbook and save it
|
|
workbook.Sheets['Sheet1'] = worksheet;
|
|
XLSX.writeFile(workbook, 'loginResults.xlsx');
|
|
} finally {
|
|
await driver.quit();
|
|
}
|
|
})();
|
|
}
|
|
|
|
export default ExACT_login;
|