AVT-1029 Add test "Verify the production logs exists when clicking on "Show logs in Explorer"" (#445)

This commit is contained in:
thaisym1912
2018-08-02 17:23:46 +07:00
committed by Vishwas Shashidhar
parent 33b3e0840b
commit e441deeb1d
6 changed files with 146 additions and 13 deletions

View File

@@ -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();

View File

@@ -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_"
};

View File

@@ -28,7 +28,6 @@ class App {
}
this.app = new Application(this.options);
this.pathApp = '';
}
async startApplication(configurations) {
@@ -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);

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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 {
@@ -64,6 +66,77 @@ class WindowsActions {
})
}
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) {
await expect(minimized).toBeTruthy();