import { Builder, By, Key, until } from 'selenium-webdriver'; import fs from 'fs'; import XLSX from 'xlsx'; import path from 'path'; const ExACT_login = (req, res) => { res.send('

ExACT Automated Test Script - Login(ExACT_login): Initiated

'); (async function example() { let driver = await new Builder().forBrowser('chrome').build(); let testStatus = 'Failed'; let workbook; let worksheet; const startTime = new Date().toISOString(); //Welcome back const expectedWelcomeBackText = 'WELCOME BACK!'; //Login const expectedLoginTitleText = 'Login to your account'; //Username const expectedUsernameLabel = 'Username'; const expectedUsernamePlaceholder = 'Username'; //Password const expectedPasswordLabel = 'Password'; const expectedPasswordPlaceholder = 'Password'; //Login button const expectedLoginButtonText = 'Login'; //Don't have account text const expectedDontHaveAccountText = `DON'T HAVE AN ACCOUNT?`; //Free trial button const expectedFreeTrialButtonText = '30 Day'; //Validation const expectedAuthenticationText = 'Authentication Failed. Please check the username and password you entered and try again.'; //Signed in Username const expectedUsername = 'JuanIsThe BestAdmin'; 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) { throw new Error('ExACT logo not found'); } console.log('Passed: ExACT logo present'); } }, //Welcome back text { description: 'Validate Welcome back text', action: async () => { const elementText = await driver.findElement(By.css('#formLogin > p')).getText(); if (elementText !== expectedWelcomeBackText) { throw new Error(`Expected: "${expectedWelcomeBackText}"; Actual: "${elementText}"`); } console.log('Passed: Welcome Back! text matched as expected'); } }, //Welcome back text color -gray { description: 'Validate Welcome back text color', action: async () => { const elementStyle = await driver.findElement(By.css('#formLogin > p')).getCssValue('color'); if (elementStyle !== 'rgba(117, 117, 117, 1)') { throw new Error(`Welcome back text color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Welcome back text color matched as expected'); } }, //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) { throw new Error('Welcome back icon not found'); } console.log('Passed: Welcome back icon present'); } }, //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) { throw new Error(`Expected: "${expectedLoginTitleText}"; Actual: "${elementText}"`); } console.log('Passed: Login title text matched as expected'); } }, //Login title text color -navy blue { description: 'Validate Login title text color', action: async () => { const elementStyle = await driver.findElement(By.css('h2:nth-child(3)')).getCssValue('color'); if (elementStyle !== 'rgba(40, 39, 90, 1)') { throw new Error(`Login title text color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Login title text color matched as expected'); } }, //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 !== '32px') { throw new Error(`Login title text font-size did not match; Actual: "${elementStyle}"`); } console.log('Passed: Login title text font-size matched as expected'); } }, //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) { throw new Error(`Expected: "${expectedUsernameLabel}"; Actual: "${elementText}"`); } console.log('Passed: Username label text matched as expected'); } }, //Username label text color -navy blue { 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 !== 'rgba(40, 39, 90, 1)') { throw new Error(`Username label text color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Username label text color matched as expected'); } }, //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) { throw new Error(`Username placeholder text Expected: "${expectedUsernamePlaceholder}"; Actual: "${elementValue}"`); } console.log('Passed: Username placeholder text matched as expected'); } }, //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) { throw new Error(`Expected: "${expectedPasswordLabel}"; Actual: "${elementText}"`); } console.log('Passed: Password label text matched as expected'); } }, //Password label text color -navy blue { 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 !== 'rgba(40, 39, 90, 1)') { throw new Error(`Password label text color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Password label text color matched as expected'); } }, //Password textbox placeholder { description: 'Validate Password placeholder text', action: async () => { const elementValue = await driver.findElement(By.css('.passfield')).getAttribute('placeholder'); if (elementValue !== expectedPasswordPlaceholder) { throw new Error(`Password placeholder text Expected: "${expectedPasswordPlaceholder}"; Actual: "${elementValue}"`); } console.log('Passed: Password placeholder text matched as expected'); } }, //Forgot password text link color -navy blue { description: 'Validate Forgot Password link text color', action: async () => { const elementStyle = await driver.findElement(By.linkText('Forgot Password?')).getCssValue('color'); if (elementStyle !== 'rgba(40, 39, 90, 1)') { throw new Error(`Forgot password link text color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Forgot password link text color matched as expected'); } }, //Login button text { description: 'Validate Login button text', action: async () => { const elementText = await driver.findElement(By.css('.login')).getAttribute('value'); if (elementText !== expectedLoginButtonText) { throw new Error(`Expected: "${expectedLoginButtonText}"; Actual: "${elementText}"`); } console.log('Passed: Login button text matched as expected'); } }, //Login button background color -teal { description: 'Validate Login button background color', action: async () => { const elementStyle = await driver.findElement(By.css('.login')).getCssValue('background-color'); if (elementStyle !== 'rgba(48, 200, 172, 1)') { throw new Error(`Login button background color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Login button background color matched as expected'); } }, //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) { throw new Error(`Expected: "${expectedDontHaveAccountText}"; Actual: "${elementText}"`); } console.log('Passed: Dont have an account text matched as expected'); } }, //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) { throw new Error(`Expected: "${expectedFreeTrialButtonText}"; Actual: "${elementText}"`); } console.log('Passed: Free trial button text matched as expected'); } }, //Free trial button background color -white { description: 'Validate Free trial button background color', action: async () => { const elementStyle = await driver.findElement(By.css('.btn > span')).getCssValue('background-color'); if (elementStyle !== 'rgba(0, 0, 0, 0)') { throw new Error(`Free trial button background color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Free trial button background color matched as expected'); } }, //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) { throw new Error('EdGate copyright not found'); } console.log('Passed: EdGate copyright image present'); } }, //Validation { description: 'Click Login button without username or password', action: async () => await driver.findElement(By.css('.login')).click() }, { description: 'Driver sleep', action: async () => await driver.sleep(2000) }, /*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: 'Driver sleep', action: async () => await driver.sleep(2000) }, { 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: 'Driver sleep', action: async () => await driver.sleep(2000) }, //Confirm validation message { description: 'Verify authentication failed validation text', action: async () => { const elementText = await driver.findElement(By.css('.alert')).getText(); if (elementText !== expectedAuthenticationText) { throw new Error(`Expected: "${expectedAuthenticationText}"; Actual: "${elementText}"`); } console.log('Passed: Authentication text matched as expected'); } }, //Authentication validation text background color -red/orange { description: 'Validate authentication alert background color', action: async () => { const elementStyle = await driver.findElement(By.css('.alert')).getCssValue('background-color'); if (elementStyle !== 'rgba(231, 76, 60, 0.88)') { throw new Error(`Authentication alert background color did not match; Actual: "${elementStyle}"`); } console.log('Passed: Authentication alert background color matched as expected'); } }, { 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) }, //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 () => { const elementText = await driver.findElement(By.css('#navbarDropdown > span')).getText(); if (elementText !== expectedUsername) { throw new Error(`Expected: "${expectedUsername}"; Actual: "${elementText}"`); } console.log('Passed: Username matched as expected'); } }, //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) => { 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', 'login'); const screenshotFileName = `step_${stepIndex}_${stepDescription.replace(/\s+/g, '_')}.png`; const screenshotPath = path.join(dir, screenshotFileName); fs.writeFileSync(screenshotPath, screenshot, 'base64'); 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 }); //Remove old Excel file if (fs.existsSync('loginResults.xlsx')) { fs.unlinkSync('loginResults.xlsx'); } }; try { //Initialize workbook and worksheet clearOldResults(); //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 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(); 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) { //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; } } //Check if log out was successful const loginButton = await driver.wait(until.elementLocated(By.css('.login')), 5000).catch(() => false); if (loginButton && allStepsPassed) { console.log('PASSED: Login(ExACT_login); All test steps completed successfully'); testStatus = 'Passed'; } else { console.log('FAILED: Login(ExACT_login); One or more test steps failed'); testStatus = 'Failed'; } //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 workbook.Sheets['Sheet1'] = worksheet; XLSX.writeFile(workbook, 'loginResults.xlsx'); } finally { await driver.quit(); } })(); } export default ExACT_login;