Files
EdGateAutomatedRegression/tests/ExACT_landingPage.js

588 lines
21 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';
const ExACT_landingPage = (req, res) => {
res.send('<h2>ExACT Automated Test Script: ExACT Landing Page(ExACT_landingPage); 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();
//Left Panel:
//Title
const expectedTitleText = 'Empowering publishers with the ability to correlate their unique content to standards.';
//Description
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.';
//Sign Up
const expectedSignUpText = 'Sign Up For A 30 Day Free Trial';
//Bullet Points
const expectedBulletPointText1 = 'Learn more about ExACT AutoAlign, the AI-based alignment tool.';
const expectedBulletPointText2 = 'See your Correlation Analytics.';
const expectedBulletPointText3 = 'Explore how your Content maps to International Standards.';
//Right Panel:
//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';
//Forgot password link
//Login button
const expectedLoginButtonText = 'Login';
//Don't have account text
const expectedDontHaveAccountText = `DON'T HAVE AN ACCOUNT?`;
//Free trial button
const expectedFreeTrialButtonText = '30 Day';
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() },
//LEFT PANEL
//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) {
throw new Error(`Expected: "${expectedTitleText}"; Actual: "${elementText}"`);
}
console.log('Passed: Title text matched as expected');
}
},
//Title text font
{
description: 'Validate 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(`Title text font-size did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Title text font-size matched as expected');
}
},
//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) {
throw new Error(`Expected: "${expectedDescriptiveText1}"; Actual: "${elementText}"`);
}
console.log('Passed: Descriptive text 1 matched as expected');
}
},
//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) {
throw new Error(`Expected: "${expectedDescriptiveText2}"; Actual: "${elementText}"`);
}
console.log('Passed: Descriptive text 2 matched as expected');
}
},
//Sign Up text
{
description: 'Validate sign up text',
action: async () =>
{ const elementText = await driver.findElement(By.css('h4')).getText();
if (elementText !== expectedSignUpText) {
throw new Error(`Expected: "${expectedSignUpText}"; Actual: "${elementText}"`);
}
console.log('Passed: Sign up text matched as expected');
}
},
//Free trial link text color -red/orange
{
description: 'Validate free trial link color',
action: async () =>
{ const elementStyle = await driver.findElement(By.linkText('30 Day Free Trial')).getCssValue('color');
if (elementStyle !== 'rgba(255, 111, 97, 1)') {
throw new Error(`Free trial link text color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Free trial link text color matched as expected');
}
},
//Bullet Point Icon 1
{
description: 'Verify bullet point icon 1 is present',
action: async () =>
{ const expectedbulletPointIcon = await driver.wait(until.elementLocated(By.css('li:nth-child(1) img')), 5000).catch(() => false);
if (!expectedbulletPointIcon) {
throw new Error('Bullet Point Icon 1 not found');
}
console.log('Passed: Bullet Point Icon 1 present');
}
},
//Bullet Point 1 text
{
description: 'Validate bullet point 1 text',
action: async () =>
{ const elementText = await driver.findElement(By.css('li:nth-child(1) > .list-flex')).getText();
if (elementText !== expectedBulletPointText1) {
throw new Error(`Expected: "${expectedBulletPointText1}"; Actual: "${elementText}"`);
}
console.log('Passed: Bullet point 1 text matched as expected');
}
},
//Bullet Point link 1 text color -teal
{
description: 'Validate bullet point link 1 text color',
action: async () =>
{ const elementStyle = await driver.findElement(By.linkText('ExACT AutoAlign,')).getCssValue('color');
if (elementStyle !== 'rgba(48, 200, 172, 1)') {
throw new Error(`Bullet point link 1 text color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Bullet point link 1 text color matched as expected');
}
},
//Bullet Point Icon 2
{
description: 'Verify bullet point icon 2 is present',
action: async () =>
{ const expectedbulletPointIcon = await driver.wait(until.elementLocated(By.css('li:nth-child(2) img')), 5000).catch(() => false);
if (!expectedbulletPointIcon) {
throw new Error('Bullet Point Icon 2 not found');
}
console.log('Passed: Bullet Point Icon 2 present');
}
},
//Bullet Point 2 text
{
description: 'Validate bullet point 2 text',
action: async () =>
{ const elementText = await driver.findElement(By.css('li:nth-child(2) > .list-flex')).getText();
if (elementText !== expectedBulletPointText2) {
throw new Error(`Expected: "${expectedBulletPointText2}"; Actual: "${elementText}"`);
}
console.log('Passed: Bullet point 2 text matched as expected');
}
},
//Bullet Point link 2 text color -teal
{
description: 'Validate bullet point link 2 text color',
action: async () =>
{ const elementStyle = await driver.findElement(By.linkText('Correlation Analytics.')).getCssValue('color');
if (elementStyle !== 'rgba(48, 200, 172, 1)') {
throw new Error(`Bullet point link 2 text color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Bullet point link 2 text color matched as expected');
}
},
//Bullet Point Icon 3
{
description: 'Verify bullet point icon 3 is present',
action: async () =>
{ const expectedbulletPointIcon = await driver.wait(until.elementLocated(By.css('li:nth-child(3) img')), 5000).catch(() => false);
if (!expectedbulletPointIcon) {
throw new Error('Bullet Point Icon 3 not found');
}
console.log('Passed: Bullet Point Icon 3 present');
}
},
//Bullet Point 3 text
{
description: 'Validate bullet point 3 text',
action: async () =>
{ const elementText = await driver.findElement(By.css('li:nth-child(3) > .list-flex')).getText();
if (elementText !== expectedBulletPointText3) {
throw new Error(`Expected: "${expectedBulletPointText3}"; Actual: "${elementText}"`);
}
console.log('Passed: Bullet point 3 text matched as expected');
}
},
//Bullet Point link 3 text color -teal
{
description: 'Validate bullet point link 3 text color',
action: async () =>
{ const elementStyle = await driver.findElement(By.linkText('International Standards.')).getCssValue('color');
if (elementStyle !== 'rgba(48, 200, 172, 1)') {
throw new Error(`Bullet point link 3 text color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Bullet point link 3 text color matched as expected');
}
},
//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 (alt to .getText)
{
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');
}
},
];
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', 'landingPage');
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', 'landingPage');
if (fs.existsSync(screenshotDir)) {
fs.rmSync(screenshotDir, { recursive: true, force: true });
}
fs.mkdirSync(screenshotDir, { recursive: true });
//Remove old Excel file
if (fs.existsSync('landingPageResults.xlsx')) {
fs.unlinkSync('landingPageResults.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;
}
}
//Script completed
const expectedEdGateCopyright = await driver.wait(until.elementLocated(By.css('.logincopyright > img')), 5000).catch(() => false);
if (expectedEdGateCopyright && allStepsPassed) {
console.log('PASSED: ExACT Landing Page(ExACT_landingPage); All test steps completed successfully');
testStatus = 'Passed';
} else {
console.log('FAILED: ExACT Landing Page(ExACT_landingPage); 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, 'landingPageResults.xlsx');
} finally {
await driver.quit();
}
})();
}
export default ExACT_landingPage;