Files
EdGateAutomatedRegression/tests/ExACT_landingPage.js
2024-10-03 16:12:44 -07:00

237 lines
10 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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_landingPage = (req, res) => {
res.send('<h2>ExACT Automated Test Script - Landing Page: 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();
//Text to be verified
const expectedTitleText = 'Empowering publishers with the ability to correlate their unique content to standards.';
const expectedDescriptiveText1 = 'The ExACT platform is the education industry’s most trusted source to globally correlate content to standards and produce content alignment reports.';
const expectedDescriptiveText2 = 'With access to over five million learning outcomes, ExACT’s robust toolset allows end users to discover new markets for their content, find gaps, and adjust alignments for specific opportunities.';
const expectedSignUpText = 'Sign Up For A 30 Day Free Trial';
const expectedFreeTrialLink = '30 Day Free Trial';
const expectedBulletPoint1 = 'Learn more about ExACT AutoAlign, the AI-based alignment tool.';
const expectedBulletPointLink1 = 'ExACT AutoAlign,';
const expectedBulletPoint2 = 'See your Correlation Analytics.';
const expectedBulletPointLink2 = 'Correlation Analytics.';
const expectedBulletPoint3 = 'Explore how your Content maps to International Standards.';
const expectedBulletPointLink3 = 'International Standards.';
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() },
//Title text
{ description: 'Wait for title text to be present', action: async () => await driver.wait(until.elementLocated(By.css('h2:nth-child(1)')), 5000) },
{ description: 'Validate title text', action: async () =>
{ const elementText = await driver.findElement(By.css('h2:nth-child(1)')).getText();
if (elementText === expectedTitleText)
{console.log('Passed: Title matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedTitleText}", but found "${elementText}"`);}
}
},
//Descriptive text 1
{ description: 'Validate descriptive text 1', action: async () =>
{ const elementText = await driver.findElement(By.css('.content-inner > p:nth-child(2)')).getText();
if (elementText === expectedDescriptiveText1)
{console.log('Passed: Descriptive text 1 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedDescriptiveText1}", but found "${elementText}"`);}
}
},
//Descriptive text 2
{ description: 'Validate descriptive text 2', action: async () =>
{ const elementText = await driver.findElement(By.css('p:nth-child(3)')).getText();
if (elementText === expectedDescriptiveText2)
{console.log('Passed: Descriptive text 2 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedDescriptiveText2}", but found "${elementText}"`);}
}
},
//Sign Up text
{ description: 'Validate sign up text', action: async () =>
{ const elementText = await driver.findElement(By.css('h4')).getText();
if (elementText === expectedSignUpText)
{console.log('Passed: Sign up text matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedSignUpText}", but found "${elementText}"`);}
}
},
//Free trial link
{ description: 'Validate free trial link', action: async () =>
{ const elementText = await driver.findElement(By.linkText('30 Day Free Trial')).getText();
if (elementText === expectedFreeTrialLink)
{console.log('Passed: Free trial link matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedFreeTrialLink}", but found "${elementText}"`);}
}
},
//Bullet Point 1
{ description: 'Validate bullet point 1', action: async () =>
{ const elementText = await driver.findElement(By.css('li:nth-child(1) > .list-flex')).getText();
if (elementText === expectedBulletPoint1)
{console.log('Passed: Bullet point 1 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedBulletPoint1}", but found "${elementText}"`);}
}
},
//Bullet Point link 1
{ description: 'Validate bullet point link 1', action: async () =>
{ const elementText = await driver.findElement(By.linkText('ExACT AutoAlign,')).getText();
if (elementText === expectedBulletPointLink1)
{console.log('Passed: Bullet pont link 1 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedBulletPointLink1}", but found "${elementText}"`);}
}
},
//Bullet Point 2
{ description: 'Validate bullet point 2', action: async () =>
{ const elementText = await driver.findElement(By.css('li:nth-child(2) > .list-flex')).getText();
if (elementText === expectedBulletPoint2)
{console.log('Passed: Bullet point 2 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedBulletPoint2}", but found "${elementText}"`);}
}
},
//Bullet Point link 2
{ description: 'Validate bullet point link 2', action: async () =>
{ const elementText = await driver.findElement(By.linkText('Correlation Analytics.')).getText();
if (elementText === expectedBulletPointLink2)
{console.log('Passed: Bullet pont link 2 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedBulletPointLink2}", but found "${elementText}"`);}
}
},
//Bullet Point 3
{ description: 'Validate bullet point 3', action: async () =>
{ const elementText = await driver.findElement(By.css('li:nth-child(3) > .list-flex')).getText();
if (elementText === expectedBulletPoint3)
{console.log('Passed: Bullet point 3 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedBulletPoint3}", but found "${elementText}"`);}
}
},
//Bullet Point link 3
{ description: 'Validate bullet point link 3', action: async () =>
{ const elementText = await driver.findElement(By.linkText('International Standards.')).getText();
if (elementText === expectedBulletPointLink3)
{console.log('Passed: Bullet pont link 3 matched as expected');}
else
{console.log(`FAILED: Expected: "${expectedBulletPointLink3}", but found "${elementText}"`);}
}
},
/*
{ description: 'Enter username', action: async () => await driver.findElement(By.id('txtU')).sendKeys('gnight147', Key.RETURN) },
{ description: 'Wait for password field to be present', action: async () => await driver.sleep(3000) },
{ description: 'Enter password', action: async () => await driver.findElement(By.id('txtP')).sendKeys('EDmin123', Key.RETURN) },
{ 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', 'landingPageScript');
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('landingPageResults.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, 'landingPageResults.xlsx');
} else {
workbook = XLSX.readFile('landingPageResults.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 landing page test was successful
const loginButton = await driver.wait(until.elementLocated(By.css('.login')), 5000).catch(() => false);
if (loginButton) {
console.log('Login button present');
testStatus = 'Passed';
} else {
console.log('Login button not found');
}
const freeTialButton = await driver.wait(until.elementLocated(By.css('.btn > span')), 5000).catch(() => false);
if (freeTialButton) {
console.log('Free Trial button present');
testStatus = 'Passed';
} else {
console.log('Free Trial button not found');
}
// 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, 'landingPageResults.xlsx');
} finally {
await driver.quit();
}
})();
}
export default ExACT_landingPage;