import { Builder, By, Key, until } from 'selenium-webdriver';
import fs from 'fs';
import XLSX from 'xlsx';
import path from 'path';
const ExACT_dashboardMyContent = (req, res) => {
res.send('
ExACT Automated Test Script - Dashboard - My Content: Initiated
');
(async function example() {
let driver = await new Builder().forBrowser('chrome').build();
let testStatus = 'Failed';
let workbook;
let worksheet;
const startTime = new Date().toISOString();
//Page title
const expectedDashboardTitle = 'Correlation Dashboard';
//My Content widget
const expectedMyContentWidgetTitle = 'My Content';
//Ellipsis
//Create Content
const expectedCreateContentSetLinkText = 'Create Content Set';
//Export Content
const expectedExportContentSetLinkText = 'Export Content Set';
//Filter
const expectedFilterPlaceholder = 'filter...';
//Sort
const expectedSortLabel = 'Sort:';
const expectedSortDropDown = 'count';
//Content
const expectedBiologyQALink = 'Biology - QA';
const expectedBiologyQACountLink = '1046';
//Edit Content Set DIV
const expectedEditDIVLabel = 'Content Set Name';
const expectedEditDIVTextbox = 'Biology - QA';
const expectedCreatedDIVTextbox = 'Automated Content Set - To be deleted'
const expectedEditDIVDeleteBtn = 'Delete';
const expectedEditDIVSaveBtn = 'Save';
const expectedEditDIVCloseBtn = 'Close';
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() },
//Login
{ description: 'Enter username', action: async () => await driver.findElement(By.css('.form-control:nth-child(2)')).sendKeys('exact_juan') },
{ description: 'Enter password', action: async () => await driver.findElement(By.css('.passfield')).sendKeys('Edgate1!') },
{ description: 'Click Login button', action: async () => await driver.findElement(By.css('.login')).click() },
{ description: 'Wait for login process to complete', action: async () => await driver.sleep(10000) },
//Dashboard title
{
description: 'Validate dashboard title',
action: async () => {
const elementText = await driver.findElement(By.css('.e-heading')).getText();
if (elementText !== expectedDashboardTitle) {
throw new Error(`Expected: "${expectedWelcomeBackText}"; Actual: "${elementText}"`);
}
console.log('Passed: Dashboard title matched as expected');
}
},
//Dashboard title text color -navy blue
{
description: 'Validate dashboard title text color',
action: async () => {
const elementStyle = await driver.findElement(By.css('.e-heading')).getCssValue('color');
if (elementStyle !== 'rgba(40, 39, 90, 1)') {
throw new Error(`Dashboard title text color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Dashboard title text color matched as expected');
}
},
//Dashboard title text font
{
description: 'Validate dashboard title text font size',
action: async () => {
const elementStyle = await driver.findElement(By.css('.e-heading')).getCssValue('font-size');
if (elementStyle !== '32px') {
throw new Error(`Dashboard title text fond-size did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Dashboard title text font-size matched as expected');
}
},
//Widget title
{
description: 'Validate widget title',
action: async () => {
const elementText = await driver.findElement(By.css('.h-100 h2:nth-child(2)')).getText();
if (elementText !== expectedMyContentWidgetTitle) {
throw new Error(`Expected: "${expectedMyContentWidgetTitle}"; Actual: "${elementText}"`);
}
console.log('Passed: Widget title matched as expected');
}
},
//Widget title text color -navy blue
{
description: 'Validate widget title text color',
action: async () => {
const elementStyle = await driver.findElement(By.css('.h-100 h2:nth-child(2)')).getCssValue('color');
if (elementStyle !== 'rgba(40, 39, 90, 1)') {
throw new Error(`Widget title text color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Widget title text color matched as expected');
}
},
//Widget title text font
{
description: 'Validate widget title text font size',
action: async () => {
const elementStyle = await driver.findElement(By.css('.h-100 h2:nth-child(2)')).getCssValue('font-size');
if (elementStyle !== '18px') {
throw new Error(`Widget title text font-size did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Widget title text font-size matched as expected');
}
},
//Ellipsis icon color -navy blue
{
description: 'Validate ellipsis icon color',
action: async () => {
const elementStyle = await driver.findElement(By.css('.fa-ellipsis-h')).getCssValue('color');
if (elementStyle !== 'rgba(40, 39, 90, 1)') {
throw new Error(`Ellipsis icon color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Ellipsis icon color matched as expected');
}
},
//Search icon color -dark blue
{
description: 'Validate search icon color',
action: async () => {
const elementStyle = await driver.findElement(By.css('.col-12 > .fa')).getCssValue('color');
if (elementStyle !== 'rgba(40, 39, 90, 1)') {
throw new Error(`Search icon color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Search icon color matched as expected');
}
},
//Filter textbox placeholder
{
description: 'Validate Filter placeholder text',
action: async () => {
const elementValue = await driver.findElement(By.css('#content-org-filter')).getAttribute('placeholder');
if (elementValue !== expectedFilterPlaceholder) {
throw new Error(`Expected: "${expectedFilterPlaceholder}"; Actual: "${elementValue}"`);
}
console.log('Passed: Filter placeholder text matched as expected');
}
},
//Sort
{
description: 'Validate sort label',
action: async () => {
const elementText = await driver.findElement(By.css('.col-4')).getText();
if (elementText !== expectedSortLabel) {
throw new Error(`Expected: "${expectedSortLabel}"; Actual: "${elementText}"`);
}
console.log('Passed: Sort label matched as expected');
}
},
//Sort Dropdown
{
description: 'Validate sort dropdown option',
action: async () => {
const elementOption = await driver.findElement(By.css('#orgsort')).getAttribute('value');
if (elementOption !== expectedSortDropDown) {
throw new Error(`Expected: "${expectedSortDropDown}"; Actual: "${elementOption}"`);
}
console.log('Passed: Sort dropdown option matched as expected');
}
},
//Biology-QA
{
description: 'Validate Biology-QA title',
action: async () => {
const elementText = await driver.findElement(By.linkText('Biology - QA')).getText();
if (elementText !== expectedBiologyQALink) {
throw new Error(`Expected: "${expectedBiologyQALink}"; Actual: "${elementText}"`);
}
console.log('Passed: Biology-QA title matched as expected');
}
},
//Biology-QA Edit icon
{
description: 'Verify Biology-QA edit icon is present',
action: async () => {
const expectedBiologyQAEditIcon = await driver.wait(until.elementLocated(By.css('#mycontentlist > #content-org-list > .content-org .fa')), 5000).catch(() => false);
if (!expectedBiologyQAEditIcon) {
throw new Error('Biology-QA edit icon not found');
}
console.log('Passed: Biology-QA edit icon present');
}
},
//Biology-QA count
{
description: 'Validate Biology-QA count',
action: async () => {
const elementText = await driver.findElement(By.css('#mycontentlist > #content-org-list > .content-org .badge')).getText();
if (elementText !== expectedBiologyQACountLink) {
throw new Error(`Expected: "${expectedBiologyQACountLink}"; Actual: "${elementText}"`);
}
console.log('Passed: Biology-QA count matched as expected');
}
},
//Add Content Set
{ description: 'Click Biology-QA edit icon', action: async () => await driver.findElement(By.css('#mycontentlist > #content-org-list > .content-org .fa')).click() },
//Wait for DIV
{
description: 'Wait for DIV to open',
action: async () => {
return await driver.wait(until.elementLocated(By.css('.modal-content .modal-title')), 50000).catch(() => false);
}
},
//Edit Content Set DIV
{
description: 'Validate edit DIV title',
action: async () => {
const elementText = await driver.findElement(By.css('.modal-content .modal-title')).getText();
if (elementText !== 'Edit Content Set') {
throw new Error(`Edit DIV title did not match; Actual: "${elementText}"`);
}
console.log('Passed: Edit DIV title matched as expected');
}
},
//Edit Content Set DIV - label
{
description: 'Validate edit DIV label',
action: async () => {
const elementText = await driver.findElement(By.css('.form-label')).getText();
if (elementText !== expectedEditDIVLabel) {
throw new Error(`Expected: "${expectedEditDIVLabel}"; Actual: "${elementText}"`);
}
console.log('Passed: Edit DIV label matched as expected');
}
},
//Edit Content Set DIV - textbox
{
description: 'Validate edit DIV textbox',
action: async () => {
const elementValue = await driver.findElement(By.css('#orgname')).getAttribute('value');
if (elementValue !== expectedEditDIVTextbox) {
throw new Error(`Edit DIV textbox Expected: "${expectedEditDIVTextbox}"; Actual: "${elementValue}"`);
}
console.log('Passed: Edit DIV textbox matched as expected');
}
},
//Edit Content Set DIV - Delete button
{
description: 'Validate edit DIV delete text button',
action: async () => {
const elementText = await driver.findElement(By.css('#orgdelete')).getText();
if (elementText !== expectedEditDIVDeleteBtn) {
throw new Error(`Expected: "${expectedEditDIVDeleteBtn}"; Actual: "${elementText}"`);
}
console.log('Passed: Edit DIV delete text button matched as expected');
}
},
//Edit Content Set DIV - Delete button color -red
{
description: 'Validate edit DIV delete button color',
action: async () => {
const elementStyle = await driver.findElement(By.css('#orgdelete')).getCssValue('background-color');
if (elementStyle !== 'rgba(220, 53, 69, 1)') {
throw new Error(`Edit DIV delete button color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Edit DIV delete button color matched as expected');
}
},
//Edit Content Set DIV - Save button
{
description: 'Validate edit DIV save text button',
action: async () => {
const elementText = await driver.findElement(By.css('#modalop')).getAttribute('value');
if (elementText !== expectedEditDIVSaveBtn) {
throw new Error(`Expected: "${expectedEditDIVSaveBtn}"; Actual: "${elementText}"`);
}
console.log('Passed: Edit DIV save text button matched as expected');
}
},
//Edit Content Set DIV - Save button color -green
{
description: 'Validate edit DIV save button color',
action: async () => {
const elementStyle = await driver.findElement(By.css('#modalop')).getCssValue('background-color');
if (elementStyle !== 'rgba(48, 200, 172, 1)') {
throw new Error(`Edit DIV save button color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Edit DIV save button color matched as expected');
}
},
//Edit Content Set DIV - Close button
{
description: 'Validate edit DIV close text button',
action: async () => {
const elementText = await driver.findElement(By.css('#modalclose')).getText();
if (elementText !== expectedEditDIVCloseBtn) {
throw new Error(`Expected: "${expectedEditDIVCloseBtn}"; Actual: "${elementText}"`);
}
console.log('Passed: Edit DIV close text button matched as expected');
}
},
//Edit Content Set DIV - Close button color -white
{
description: 'Validate edit DIV close button color',
action: async () => {
const elementStyle = await driver.findElement(By.css('#modalclose')).getCssValue('background-color');
if (elementStyle !== 'rgba(0, 0, 0, 0)') {
throw new Error(`Edit DIV close button color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Edit DIV close button color matched as expected');
}
},
//Close edit DIV
{ description: 'Click X icon', action: async () => await driver.findElement(By.css('.modal-content > .modal-header span')).click() },
//Ellipsis
{ description: 'Click ellipsis icon', action: async () => await driver.findElement(By.css('.fa-ellipsis-h')).click() },
{ description: 'Driver sleep', action: async () => await driver.sleep(2000) },
//Create Content Set icon color -dark blue
{
description: 'Validate create content set icon color',
action: async () => {
const elementStyle = await driver.findElement(By.css('.fa-plus')).getCssValue('color');
if (elementStyle !== 'rgba(33, 37, 41, 1)') {
throw new Error(`Create Content Set icon color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Create Content Set icon color matched as expected');
}
},
//Create Content Set link text
{
description: 'Validate create content set link text',
action: async () => {
const elementText = await driver.findElement(By.linkText('Create Content Set')).getText();
if (elementText !== expectedCreateContentSetLinkText) {
throw new Error(`Expected: "${expectedCreateContentSetLinkText}"; Actual: "${elementText}"`);
}
console.log('Passed: Create Content Set link text matched as expected');
}
},
//Create Content Set link text color -dark blue
{
description: 'Validate create content set link text color',
action: async () => {
const elementStyle = await driver.findElement(By.linkText('Create Content Set')).getCssValue('color');
if (elementStyle !== 'rgba(33, 37, 41, 1)') {
throw new Error(`Create Content Set link text color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Create Content Set link text color matched as expected');
}
},
//Export Content Set icon color -dark blue
{
description: 'Validate export content set icon color',
action: async () => {
const elementStyle = await driver.findElement(By.css('.fa-download')).getCssValue('color');
if (elementStyle !== 'rgba(33, 37, 41, 1)') {
throw new Error(`Export Content icon color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Export Content icon color matched as expected');
}
},
//Export Content Set link text
{
description: 'Validate export content set link text',
action: async () => {
const elementText = await driver.findElement(By.linkText('Export Content Set')).getText();
if (elementText !== expectedExportContentSetLinkText) {
throw new Error(`Expected: "${expectedExportContentSetLinkText}"; Actual: "${elementText}"`);
}
console.log('Passed: Export Content Set link text matched as expected');
}
},
//Export Content Set link text color -dark blue
{
description: 'Validate export content set link text color',
action: async () => {
const elementStyle = await driver.findElement(By.linkText('Export Content Set')).getCssValue('color');
if (elementStyle !== 'rgba(33, 37, 41, 1)') {
throw new Error(`Export Content Set icon color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Export Content Set icon color matched as expected');
}
},
//Create Content Set
{ description: 'Click ellipsis icon', action: async () => await driver.findElement(By.linkText('Create Content Set')).click() },
//Wait for DIV
{
description: 'Wait for DIV to open',
action: async () => {
return await driver.wait(until.elementLocated(By.css('.modal-content .modal-title')), 50000).catch(() => false);
}
},
//Create Content Set DIV
{
description: 'Validate create content set DIV title',
action: async () => {
const elementText = await driver.findElement(By.css('.modal-content .modal-title')).getText();
if (elementText !== 'Create Content Set') {
throw new Error(`Content set DIV title did not match; Actual: "${elementText}"`);
}
console.log('Passed: Create content set DIV title matched as expected');
}
},
//Create Content Set DIV - label
{
description: 'Validate create DIV label',
action: async () => {
const elementText = await driver.findElement(By.css('.form-label')).getText();
if (elementText !== expectedEditDIVLabel) {
throw new Error(`Expected: "${expectedEditDIVLabel}"; Actual: "${elementText}"`);
}
console.log('Passed: Create DIV label matched as expected');
}
},
//Enter Content Set Name
{ description: 'Enter content set name', action: async () => await driver.findElement(By.css('#orgname')).sendKeys('Automated Content Set - To be deleted') },
{ description: 'Click create button', action: async () => await driver.findElement(By.css('#modalop')).click() },
//{ description: 'Driver sleep', action: async () => await driver.sleep(5000) },
//Wait for confirmation message
{
description: 'Wait for DIV to open',
action: async () => {
return await driver.wait(until.elementLocated(By.css('strong:nth-child(1)')), 50000).catch(() => false);
}
},
//Validate confirmation message
{
description: 'Validate confirmation message',
action: async () => {
const elementText = await driver.findElement(By.css('strong:nth-child(1)')).getText();
if (elementText !== 'The content set was successfuly created') {
throw new Error(`Expected confirmation message did not match; Actual: "${elementText}"`);
}
console.log('Passed: Confirmation message displayed as expected');
}
},
//Validate confirmation message background color -green
{
description: 'Validate confirmation message background color',
action: async () => {
const elementStyle = await driver.findElement(By.css('#statalert')).getCssValue('background-color');
if (elementStyle !== 'rgba(40, 167, 69, 1)') {
throw new Error(`Confirmation message background color did not match; Actual: "${elementStyle}"`);
}
console.log('Passed: Confirmation background color matched as expected');
}
},
//Validate created content set
{
description: 'Verify created automated content set',
action: async () => {
const expectedCreatedContentSet = await driver.wait(until.elementLocated(By.linkText('Automated Content Set - To be deleted')), 5000).catch(() => false);
if (!expectedCreatedContentSet) {
throw new Error('Automated created content set not found');
}
console.log('Passed: Automated content set present');
}
},
//Click created content set
{ description: 'Click created content set edit icon', action: async () => await driver.findElement(By.css('#content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list > #content-org-list .fa')).click() },
//Wait for DIV
{
description: 'Wait for DIV to open',
action: async () => {
return await driver.wait(until.elementLocated(By.css('.modal-content .modal-title')), 50000).catch(() => false);
}
},
//Edit Content Set DIV
{
description: 'Validate edit DIV title',
action: async () => {
const elementText = await driver.findElement(By.css('.modal-content .modal-title')).getText();
if (elementText !== 'Edit Content Set') {
throw new Error(`Edit DIV title did not match; Actual: "${elementText}"`);
}
console.log('Passed: Edit DIV title matched as expected');
}
},
//Edit Content Set DIV - label
{
description: 'Validate edit DIV label',
action: async () => {
const elementText = await driver.findElement(By.css('.form-label')).getText();
if (elementText !== expectedEditDIVLabel) {
throw new Error(`Expected: "${expectedEditDIVLabel}"; Actual: "${elementText}"`);
}
console.log('Passed: Edit DIV label matched as expected');
}
},
//Edit Content Set DIV - textbox
{
description: 'Validate edit DIV textbox',
action: async () => {
const elementValue = await driver.findElement(By.css('#orgname')).getAttribute('value');
if (elementValue !== expectedCreatedDIVTextbox) {
throw new Error(`Edit DIV textbox Expected: "${expectedCreatedDIVTextbox}"; Actual: "${elementValue}"`);
}
console.log('Passed: Edit DIV textbox matched as expected');
}
},
//Delete created content set
{ description: 'Click delete button', action: async () => await driver.findElement(By.css('#orgdelete')).click() },
{ description: 'Driver sleep', action: async () => await driver.sleep(2000) },
];
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', 'dashboardMyContent');
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', 'dashboardMyContent');
if (fs.existsSync(screenshotDir)) {
fs.rmSync(screenshotDir, { recursive: true, force: true });
}
fs.mkdirSync(screenshotDir, { recursive: true });
// Remove old Excel file
if (fs.existsSync('dashboardMyContentResults.xlsx')) {
fs.unlinkSync('dashboardMyContentResults.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, '');
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);
console.error(`Step ${stepIndex} FAILED: ${error.message}`);
testStatus = 'Failed';
}
}
//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');
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, 'dashboardMyContentResults.xlsx');
} finally {
await driver.quit();
}
})();
}
export default ExACT_dashboardMyContent;