diff --git a/tests/spectron/electronProductionLogging.spectron.js b/tests/spectron/electronProductionLogging.spectron.js new file mode 100644 index 00000000..0216ae47 --- /dev/null +++ b/tests/spectron/electronProductionLogging.spectron.js @@ -0,0 +1,52 @@ +const Application = require('./spectronSetup'); +const WindowsActions = require('./spectronWindowsActions'); +const { isMac } = require('../../js/utils/misc.js'); +const Utils = require('./spectronUtils'); + +let app; +let windowActions; + +!isMac ? describe('Tests for Electron Production Logging', () => { + + let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); + + beforeAll(async (done) => { + try { + app = await new Application({}).startApplication(); + windowActions = await new WindowsActions(app); + await windowActions.deleteAllLogFiles(); + done(); + } catch (err) { + done.fail(new Error(`Unable to start application error: ${err}`)); + }; + }); + + afterAll(async (done) => { + try { + if (app && app.isRunning()) { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + await app.stop(); + done(); + } + } catch (err) { + done.fail(new Error(`Failed at post-condition: ${err}`)); + }; + }); + + /** + * Verify the production logs exists when clicking on "Show logs in Explorer" + * TC-ID: 3935260 + * Cover scenarios in AVT-1029 + */ + it('Verify the production logs exists when clicking on Show logs in Explorer', async (done) => { + try { + await windowActions.openMenu(["Help", "Troubleshooting", "Show Logs in Explorer"]); + Utils.sleep(2000) //sleep for creating log + await windowActions.verifyLogExported(); + done(); + } catch (err) { + done.fail(new Error(`Fail to export production logs with error: ${err}`)); + }; + }); +}) : describe.skip(); diff --git a/tests/spectron/spectronConstants.js b/tests/spectron/spectronConstants.js index 12fafb82..80f7df9a 100644 --- a/tests/spectron/spectronConstants.js +++ b/tests/spectron/spectronConstants.js @@ -15,8 +15,10 @@ module.exports = { { name: "Edit", step: 0, items: [{ name: "Undo", step: 0 }, { name: "Redo", step: 1 }, { name: "Cut", step: 2 }, { name: "Copy", step: 3 }, { name: "Paste", step: 4 }, { name: "Paste and Match Style", step: 5 }, { name: "Delete", step: 6 }, { name: "Select All", step: 7 }] }, { name: "View", step: 1, items: [{ name: "Reload", step: 0 }, { name: "Actual Size", step: 1 }, { name: "Zoom In", step: 2 }, { name: "Zoom Out", step: 3 }, { name: "Toogle Full Screen", step: 4 }] }, { name: "Window", step: 2, items: [{ name: "Minimize", step: 0 }, { name: "Close", step: 1 }, { name: "Auto Launch On Startup", step: 2 }, { name: "Always on Top", step: 3 }, { name: "Minimize on Close", step: 4 }] }, - { name: "Help", step: 3, items: [{ name: "Symphony Help", step: 0 }, { name: "Learn More", step: 1 }, { name: "Troubleshooting", step: 2 }, { name: "About Symphony", step: 3 }] } + { name: "Help", step: 3, items: [{ name: "Symphony Help", step: 0 }, { name: "Learn More", step: 1 }, { name: "Troubleshooting", step: 2, items:[{name: "Show Logs in Explorer", step: 0}] }, { name: "About Symphony", step: 3 }] } ] } - } + }, + + LOG_FILENAME_PREFIX: "logs_symphony_" }; diff --git a/tests/spectron/spectronSetup.js b/tests/spectron/spectronSetup.js index ef923ca7..2f2e2ae0 100644 --- a/tests/spectron/spectronSetup.js +++ b/tests/spectron/spectronSetup.js @@ -28,8 +28,7 @@ class App { } this.app = new Application(this.options); - this.pathApp = ''; - } + } async startApplication(configurations) { try { @@ -38,10 +37,8 @@ class App { await this.app.browserWindow.minimize(); await this.app.browserWindow.restore(); if (configurations) { - if ((typeof configurations.alwaysOnTop !== "undefined") && (configurations.alwaysOnTop === false)) { - await this.app.browserWindow.setAlwaysOnTop(false); - } else { - await this.app.browserWindow.setAlwaysOnTop(true); + if (typeof configurations.alwaysOnTop !== "undefined") { + await this.app.browserWindow.setAlwaysOnTop(configurations.alwaysOnTop); } if (configurations.testedHost) { await this.app.client.waitUntilWindowLoaded().url(configurations.testedHost); @@ -54,7 +51,6 @@ class App { if ((typeof configurations === "undefined") || (typeof configurations.defaultPosition === "undefined") || (configurations.defaultPosition === true)) { await this.app.browserWindow.center(); } - return this.app; } catch (err) { throw new Error("Unable to start application " + err); diff --git a/tests/spectron/spectronUtils.js b/tests/spectron/spectronUtils.js index 176d3b9d..e993ce87 100644 --- a/tests/spectron/spectronUtils.js +++ b/tests/spectron/spectronUtils.js @@ -1,4 +1,6 @@ const childProcess = require('child_process'); +const path = require('path'); +const fs = require('fs'); class Utils { static async openAppInMaximize(appPath) { @@ -14,6 +16,14 @@ class Utils { setTimeout(resolve, ms) }) } + + static getFolderPath(folderName){ + return path.join(require('os').homedir(), folderName); + } + + static getFiles(path){ + return fs.readdirSync(path); + } } module.exports = Utils; \ No newline at end of file diff --git a/tests/spectron/spectronWebActions.js b/tests/spectron/spectronWebActions.js index d300bf2b..ce52390d 100644 --- a/tests/spectron/spectronWebActions.js +++ b/tests/spectron/spectronWebActions.js @@ -2,10 +2,10 @@ const ui = require('./spectronInterfaces.js'); class WebActions { constructor(app) { - this.app = app; - } + this.app = app; + } - async clickMaximizeButton(){ + async clickMaximizeButton() { await this.app.client.waitForVisible(ui.MAXIMIZE_BTN, 10000).click(ui.MAXIMIZE_BTN); } diff --git a/tests/spectron/spectronWindowsActions.js b/tests/spectron/spectronWindowsActions.js index 22cd7252..2821b077 100644 --- a/tests/spectron/spectronWindowsActions.js +++ b/tests/spectron/spectronWindowsActions.js @@ -1,5 +1,7 @@ const robot = require('robotjs'); const constants = require('./spectronConstants.js'); +const Utils = require('./spectronUtils.js'); +const fs = require('fs'); const WebActions = require('./spectronWebActions.js') class WindowsActions { @@ -62,7 +64,78 @@ class WindowsActions { await this.app.browserWindow.isAlwaysOnTop().then(function (isAlwaysOnTop) { expect(isAlwaysOnTop).toBeTruthy(); }) - } + } + + async menuSearch(element, namevalue) { + if (element.name == namevalue) { + return await element; + } + else if (element.items !== undefined) { + var result; + for (var i = 0; result == null && i < element.items.length; i++) { + result = await this.menuSearch(element.items[i], namevalue); + result; + } + return await result; + } + return await null; + } + + async openMenu(arrMenu) { + var arrStep = []; + for (var i = 0; i < arrMenu.length; i++) { + var item = await this.menuSearch(constants.MENU.root, arrMenu[i]); + await arrStep.push(item); + } + await this.actionForMenus(arrStep); + return arrStep; + } + + async actionForMenus(arrMenu) { + await this.app.browserWindow.getBounds().then(async (bounds) => { + await robot.setMouseDelay(100); + let x = bounds.x + 95; + let y = bounds.y + 35; + await robot.moveMouseSmooth(x, y); + await robot.moveMouse(x, y); + await robot.mouseClick(); + await this.webAction.openApplicationMenuByClick(); + await robot.setKeyboardDelay(200); + await robot.keyTap('enter'); + for (var i = 0; i < arrMenu.length; i++) { + for (var s = 0; s < arrMenu[i].step; s++) { + await robot.keyTap('down'); + } + if (arrMenu.length > 1 && i != arrMenu.length - 1) { + //handle right keygen + await robot.keyTap('right'); + } + } + await robot.keyTap('enter'); + }); + } + + async verifyLogExported() { + let expected = false; + let path = await Utils.getFolderPath('Downloads'); + var listFiles = Utils.getFiles(path); + listFiles.forEach(function (fileName) { + if (fileName.indexOf(constants.LOG_FILENAME_PREFIX) > -1) { + expected = true; + } + }) + await expect(expected).toBeTruthy(); + } + + async deleteAllLogFiles() { + let path = await Utils.getFolderPath('Downloads'); + var listFiles = Utils.getFiles(path); + await listFiles.forEach(function (fileName) { + if (fileName.indexOf(constants.LOG_FILENAME_PREFIX) > -1) { + fs.unlinkSync(path.concat("\\", fileName)); + } + }) + } async verifyMinimizeWindows() { await this.app.browserWindow.isMinimized().then(async function (minimized) {