Added LogOut and updated test results
This commit is contained in:
@@ -4,7 +4,7 @@ import XLSX from 'xlsx';
|
||||
import path from 'path';
|
||||
|
||||
const ExACT_login = (req, res) => {
|
||||
res.send('<h2>ExACT Automated Test Script - Login: Initiated</h2>');
|
||||
res.send('<h2>ExACT Automated Test Script - Login(ExACT_login): Initiated</h2>');
|
||||
(async function example() {
|
||||
let driver = await new Builder().forBrowser('chrome').build();
|
||||
let testStatus = 'Failed';
|
||||
@@ -328,9 +328,17 @@ const steps = [
|
||||
{ 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: 'Driver sleep', action: async () => await driver.sleep(10000) },
|
||||
{ description: 'Wait for login process to complete', action: async () => await driver.sleep(10000) },
|
||||
|
||||
//Check if log out was successful - username
|
||||
//Wait for dashboard to load - Correlation Coverages View Details button
|
||||
{
|
||||
description: 'Wait for dashboard load to completely',
|
||||
action: async () => {
|
||||
return await driver.wait(until.elementLocated(By.linkText('View Details')), 10000).catch(() => false);
|
||||
}
|
||||
},
|
||||
|
||||
//Confirm username
|
||||
{
|
||||
description: 'Verify username',
|
||||
action: async () => {
|
||||
@@ -342,9 +350,20 @@ const steps = [
|
||||
}
|
||||
},
|
||||
|
||||
//Log Out
|
||||
{ description: 'Click the profile label', action: async () => await driver.findElement(By.css('#navbarDropdown > span')).click() },
|
||||
{ description: 'Click Log out link', action: async () => await driver.findElement(By.linkText('Log Out')).click() },
|
||||
//LOG OUT
|
||||
//NEXT ACTION - Log out
|
||||
{ description: 'Click Username dropdown', action: async () => await driver.findElement(By.css('#navbarDropdown > span')).click() },
|
||||
{ description: 'Wait for action to complete', action: async () => await driver.sleep(2000) },
|
||||
{ description: 'Click Log Out link', action: async () => await driver.findElement(By.linkText('Log Out')).click() },
|
||||
{ description: 'Wait for action to complete', action: async () => await driver.sleep(2000) },
|
||||
|
||||
//Wait for login screen to load
|
||||
{
|
||||
description: 'Wait for log out process to complete',
|
||||
action: async () => {
|
||||
return await driver.wait(until.elementLocated(By.css('.login')), 10000).catch(() => false);
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
const logStep = (worksheet, stepDescription, status, stepIndex, timestamp, screenshotPath) => {
|
||||
@@ -363,19 +382,19 @@ const takeScreenshot = async (driver, stepIndex, stepDescription) => {
|
||||
return screenshotPath;
|
||||
};
|
||||
|
||||
const clearOldResults = () => {
|
||||
// Remove old screenshots
|
||||
const screenshotDir = path.join('screenshots', 'login');
|
||||
if (fs.existsSync(screenshotDir)) {
|
||||
fs.rmSync(screenshotDir, { recursive: true, force: true });
|
||||
}
|
||||
fs.mkdirSync(screenshotDir, { recursive: true });
|
||||
const clearOldResults = () => {
|
||||
// Remove old screenshots
|
||||
const screenshotDir = path.join('screenshots', 'login');
|
||||
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');
|
||||
}
|
||||
};
|
||||
// Remove old Excel file
|
||||
if (fs.existsSync('loginResults.xlsx')) {
|
||||
fs.unlinkSync('loginResults.xlsx');
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
// Initialize workbook and worksheet
|
||||
@@ -391,6 +410,8 @@ try {
|
||||
// Log test start time
|
||||
worksheet = logStep(worksheet, 'Test Start', 'Started', '', startTime, '');
|
||||
|
||||
let allStepsPassed = true;
|
||||
|
||||
for (const step of steps) {
|
||||
const stepIndex = steps.indexOf(step) + 1;
|
||||
const timestamp = new Date().toISOString();
|
||||
@@ -404,17 +425,18 @@ try {
|
||||
worksheet = logStep(worksheet, step.description, 'Failed', stepIndex, timestamp, screenshotPath);
|
||||
console.error(`Step ${stepIndex} FAILED: ${error.message}`);
|
||||
testStatus = 'Failed';
|
||||
allStepsPassed = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Script completed
|
||||
//Check if log out was successful
|
||||
const loginButton = await driver.wait(until.elementLocated(By.css('.login')), 5000).catch(() => false);
|
||||
|
||||
if (loginButton) {
|
||||
console.log('PASSED: Script completed');
|
||||
if (loginButton && allStepsPassed) {
|
||||
console.log('PASSED: Login(ExACT_login); All test steps completed successfully');
|
||||
testStatus = 'Passed';
|
||||
} else {
|
||||
console.log('FAILED: Script completed');
|
||||
console.log('FAILED: Login(ExACT_login); One or more test steps failed');
|
||||
testStatus = 'Failed';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user