diff --git a/dashboardMyContentResults.xlsx b/dashboardMyContentResults.xlsx new file mode 100644 index 0000000..2a28597 Binary files /dev/null and b/dashboardMyContentResults.xlsx differ diff --git a/tests/ExACT_dashboardMyContent.js b/tests/ExACT_dashboardMyContent.js new file mode 100644 index 0000000..97df36d --- /dev/null +++ b/tests/ExACT_dashboardMyContent.js @@ -0,0 +1,343 @@ +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_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'; + const expectedDashboardTitleColor = 'rgba(40, 39, 90, 1)'; //navy blue + const expectedDashboardTitleFont = '32px'; +//My Content widget +const expectedMyContentWidgetTitle = 'My Content'; + const expectedWidgetTitleColor = 'rgba(40, 39, 90, 1)'; //navy blue + const expectedWidgetTitleFont = '18px'; +//Ellipsis +const expectedEllipsisIconColor = 'rgba(40, 39, 90, 1)'; //navy blue + //Create Content + const expectedCreateContentSetIconColor = 'rgba(33, 37, 41, 1)'; //navy blue (different?) + const expectedCreateContentSetLinkText = 'Create Content Set'; + const expectedCreateContentSetLinkTextColor = 'rgba(33, 37, 41, 1)'; //navy blue (different?) + //Export Content + const expectedExportContentSetIconColor = 'rgba(33, 37, 41, 1)'; //navy blue (different?) + const expectedExportContentSetLinkText = 'Export Content Set'; + const expectedExportContentSetLinkTextColor = 'rgba(33, 37, 41, 1)'; //navy blue (different?) +//Filter +const expectedSearchIconColor = 'rgba(40, 39, 90, 1)'; //navy blue +const expectedFilterPlaceholder = 'filter...'; +//Sort +const expectedSortLabel = 'Sort:'; +const expectedSortDropDown = 'count'; + +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 + { + description: 'Validate dashboard title text color', + action: async () => { + const elementStyle = await driver.findElement(By.css('.e-heading')).getCssValue('color'); + if (elementStyle !== expectedDashboardTitleColor) { + throw new Error(`Expected: "${expectedDashboardTitleColor}"; 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 !== expectedDashboardTitleFont) { + throw new Error(`Expected: "${expectedDashboardTitleFont}"; 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 + { + 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 !== expectedWidgetTitleColor) { + throw new Error(`Expected: "${expectedWidgetTitleColor}"; 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 !== expectedWidgetTitleFont) { + throw new Error(`Expected: "${expectedWidgetTitleFont}"; Actual: "${elementStyle}"`); + } + console.log('Passed: Widget title text font-size matched as expected'); + } + }, + + //Ellipsis icon color + { + description: 'Validate ellipsis icon color', + action: async () => { + const elementStyle = await driver.findElement(By.css('.fa-ellipsis-h')).getCssValue('color'); + if (elementStyle !== expectedEllipsisIconColor) { + throw new Error(`Expected: "${expectedEllipsisIconColor}"; Actual: "${elementStyle}"`); + } + console.log('Passed: Ellipsis icon color matched as expected'); + } + }, + + //Search icon color + { + description: 'Validate search icon color', + action: async () => { + const elementStyle = await driver.findElement(By.css('.col-12 > .fa')).getCssValue('color'); + if (elementStyle !== expectedSearchIconColor) { + throw new Error(`Expected: "${expectedSearchIconColor}"; 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'); + } + }, + + { description: 'Click ellipsis icon', action: async () => await driver.findElement(By.css('.fa-ellipsis-h')).click() }, + + //Create Content Set icon color + { + description: 'Validate create content set icon color', + action: async () => { + const elementStyle = await driver.findElement(By.css('.fa-plus')).getCssValue('color'); + if (elementStyle !== expectedCreateContentSetIconColor) { + throw new Error(`Expected: "${expectedCreateContentSetIconColor}"; 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 + { + description: 'Validate create content set link text color', + action: async () => { + const elementStyle = await driver.findElement(By.linkText('Create Content Set')).getCssValue('color'); + if (elementStyle !== expectedCreateContentSetLinkTextColor) { + throw new Error(`Expected: "${expectedCreateContentSetLinkTextColor}"; Actual: "${elementStyle}"`); + } + console.log('Passed: Create Content Set link text color matched as expected'); + } + }, + + //Export Content Set icon color + { + description: 'Validate export content set icon color', + action: async () => { + const elementStyle = await driver.findElement(By.css('.fa-download')).getCssValue('color'); + if (elementStyle !== expectedExportContentSetIconColor) { + throw new Error(`Expected: "${expectedExportContentSetIconColor}"; 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 + { + description: 'Validate export content set link text color', + action: async () => { + const elementStyle = await driver.findElement(By.linkText('Export Content Set')).getCssValue('color'); + if (elementStyle !== expectedExportContentSetLinkTextColor) { + throw new Error(`Expected: "${expectedExportContentSetLinkTextColor}"; Actual: "${elementStyle}"`); + } + console.log('Passed: Export Content Set icon color matched as expected'); + } + }, +]; + +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;