Updated AVT-1155

This commit is contained in:
Truong.Pham 2018-09-07 15:49:24 +07:00
parent f17a5788b4
commit 80422c59a1
4 changed files with 123 additions and 120 deletions

View File

@ -74,15 +74,21 @@ module.exports= {
//Inbox
INBOX_BUTTON: ".toolbar-btn-inbox",
INBOX_HEADER: ".inbox-header",
//ACP
ACP_LINK: "//button[@class='show-admin-link left-action button-reset']",
IMG_ADMIN_LOGO: "//img[@src='./img/nav_admin_logo.png']",
//LOG OUT
LOGOUT_DROPDOWN: "//div[@class='header-account']",
ADMIN_NAME: "//*[@class='account-name']",
ADMIN_LOG_OUT: "//*[text()[contains(.,'Log out')]]",
ADMIN_PAGE_TITLE: "//h2[@class='page-title']",
//INPUT SEARCH
INPUT_SEARCH_ENTITIES: "//input[@id='search-entities']"
INPUT_SEARCH_ENTITIES: "//input[@id='search-entities']",
//Symphony Electron API Demo
TAG_TEXTBOX: "#tag"
};

View File

@ -2,7 +2,8 @@ const ui = require('./spectronInterfaces.js');
const constants = require('./spectronConstants.js');
const Utils = require('./spectronUtils');
const WindowsActions = require('./spectronWindowsActions');
const { isMac } = require('../../js/utils/misc');
const robot = require('robotjs');
const { isMac, isWindowsOS } = require('../../js/utils/misc');
class WebActions {
constructor(app) {
@ -52,11 +53,25 @@ class WebActions {
}
return null;
}
async inputText(el, data) {
var obj = await this.getElementByXPath(el);
if (obj != null)
await this.app.client.setValue(el, data);
}
async getText(element) {
return await this.app.client.getText(element);
}
async getValue(element) {
return await this.app.client.getValue(element);
}
async getLocation(element) {
return await this.app.client.getLocation(element);
}
async clickAndWaitElementVisible(xpath, elementToVisible, timeOut = constants.TIMEOUT_WAIT_ELEMENT) {
await this.app.client.click(xpath).then(async () => {
await this.app.client.waitForVisible(elementToVisible, timeOut);
@ -88,6 +103,11 @@ class WebActions {
.click(selector)
}
async rightClickIfElementVisible(selector, timeOut = constants.TIMEOUT_WAIT_ELEMENT) {
await this.app.client.waitForVisible(selector, timeOut)
.rightClick(selector, 10, 10)
}
async openAlertsSettings() {
await this.clickAndWaitElementVisible(ui.SETTTING_BUTTON, ui.ALERT_OPTION);
await this.clickAndWaitElementVisible(ui.ALERT_OPTION, ui.ALERT_TAB);
@ -177,8 +197,8 @@ class WebActions {
async openACP() {
await this.clickAndWaitElementVisible(ui.SETTTING_BUTTON, ui.GENERAL_OPTION, constants.TIMEOUT_WAIT_ELEMENT);
await this.clickAndWaitElementVisible(ui.GENERAL_OPTION, ui.GENERAL_TAB,constants.TIMEOUT_WAIT_ELEMENT);
await this.clickAndWaitElementVisible(ui.ACP_LINK,ui.IMG_ADMIN_LOGO, constants.TIMEOUT_WAIT_ELEMENT);
await this.clickAndWaitElementVisible(ui.GENERAL_OPTION, ui.GENERAL_TAB, constants.TIMEOUT_WAIT_ELEMENT);
await this.clickAndWaitElementVisible(ui.ACP_LINK, ui.IMG_ADMIN_LOGO, constants.TIMEOUT_WAIT_ELEMENT);
}
async clickPlusButton() {
@ -189,8 +209,7 @@ class WebActions {
await this.clickIfElementVisible(ui.START_CHAT);
}
async logout()
{
async logout() {
await this.clickAndWaitElementVisible(ui.ADMIN_NAME, ui.ADMIN_LOG_OUT, constants.TIMEOUT_WAIT_ELEMENT);
await this.clickAndWaitElementVisible(ui.ADMIN_LOG_OUT, ui.SIGN_IN_BUTTON, constants.TIMEOUT_WAIT_ELEMENT);
}
@ -218,6 +237,7 @@ class WebActions {
}
async mouseOver(locator) {
await this.waitElementVisible(locator);
await this.app.client.moveToObject(locator);
}
@ -288,8 +308,7 @@ class WebActions {
await this.clickAndWaitElementVisible(ui.SIGNOUT_MODAL_BUTTON, ui.SIGN_IN_BUTTON, constants.TIMEOUT_PAGE_LOAD);
}
async verifyElementExist(findElement)
{
async verifyElementExist(findElement) {
let obs = await this.app.client.elements(findElement);
let len = await obs.value.length;
await expect(len).toBe(1);
@ -351,6 +370,38 @@ class WebActions {
let elements = await this.app.client.elements(locator);
return elements.value.length;
}
async navigateURL(url) {
return this.app.client.url(url)
}
async verifySpellCheckerWorking(locator, previous) {
let current = await this.getValue(locator);
await expect(current !== previous).toBeTruthy();
}
async openContextMenu(locator) {
if (isWindowsOS) {
let position = await this.getLocation(locator);
await robot.setMouseDelay(500);
await robot.moveMouse(position.x + 20, position.y + 5);
await robot.mouseToggle("down", "right");
await robot.mouseToggle("up", "right");
} else {
await this.mouseOver(locator);
//right click twice to make it work on MAC
await this.rightClickIfElementVisible(locator);
await this.rightClickIfElementVisible(locator);
}
}
async selectItemOnContextMenu(number) {
await robot.setKeyboardDelay(1000);
for (let i = 1; i <= number; i++) {
await robot.keyTap('down');
}
await robot.keyTap('enter');
}
}
module.exports = WebActions;

View File

@ -285,16 +285,6 @@ class WindowsActions {
this.app.browserWindow.setAlwaysOnTop(value);
}
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 reload() {
await this.app.browserWindow.getBounds().then(async (bounds) => {
await robot.setMouseDelay(100);
@ -606,6 +596,24 @@ class WindowsActions {
}
}
}
async verifyAppFullScreen() {
let actual = await this.app.browserWindow.isFullScreen();
await expect(actual).toBeTruthy();
}
async fullScreenOnMac() {
await robot.setMouseDelay(100);
await robot.moveMouseSmooth(205, 10);
await robot.mouseClick();
await robot.setKeyboardDelay(100);
// Key tap 5 times as "Enter Full Screen" is in the
// 5th position under view menu item
for (let i = 0; i < 5; i++) {
await robot.keyTap('down');
}
await robot.keyTap('enter');
}
}
module.exports = WindowsActions;

View File

@ -1,115 +1,53 @@
const Application = require('./spectronSetup');
const WebActions = require('./spectronWebActions');
const WindowsActions = require('./spectronWindowsActions');
const constants = require('./spectronConstants.js');
const path = require('path');
const {isMac} = require('../../js/utils/misc.js');
const robot = require('robotjs');
let app = new Application({});
const ui = require('./spectronInterfaces.js');
const { isWindowsOS } = require('../../js/utils/misc.js');
let app, windowsActions, webActions;
describe('Tests for spellChecker', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = constants.TIMEOUT_TEST_SUITE;
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
beforeAll((done) => {
app.startApplication().then((startedApp) => {
app = startedApp;
beforeAll(async (done) => {
try {
app = await new Application({}).startApplication({ testedHost: constants.TESTED_HOST, alwaysOnTop: true });
webActions = await new WebActions(app);
windowsActions = await new WindowsActions(app);
done();
}).catch((err) => {
} catch (err) {
await windowsActions.stopApp();
done.fail(new Error(`Unable to start application error: ${err}`));
});
};
});
afterAll((done) => {
if (app && app.isRunning()) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
app.stop().then(() => {
done();
}).catch((err) => {
done();
});
}
});
it('should launch the app', (done) => {
return app.client.waitUntilWindowLoaded().then(() => {
return app.client.getWindowCount().then((count) => {
expect(count === 1).toBeTruthy();
done();
}).catch((err) => {
done.fail(new Error(`spellChecker failed in getWindowCount with error: ${err}`));
});
}).catch((err) => {
done.fail(new Error(`spellChecker failed in waitUntilWindowLoaded with error: ${err}`));
});
});
it('should check window count', () => {
return app.client.url('file:///' + path.join(__dirname, '..', '..', 'demo/index.html'));
});
it('should set the misspelled word', () => {
return app.client
.windowByIndex(0)
.setValue('#tag', 'comming ')
.getValue('#tag').then((value) => {
expect(value === 'comming ').toBeTruthy();
});
});
it('should bring the app to front in windows', (done) => {
if (!isMac) {
app.browserWindow.focus();
app.browserWindow.restore();
app.browserWindow.getBounds().then((bounds) => {
robot.setMouseDelay(100);
let x = bounds.x + 200;
let y = bounds.y + 200;
robot.moveMouseSmooth(x, y);
robot.mouseClick();
done();
});
} else {
afterAll(async (done) => {
try {
await windowsActions.stopApp();
done();
}
} catch (err) {
done.fail(new Error(`Failed at post-condition: ${err}`));
};
});
it('should invoke context menu ', (done) => {
if (isMac) {
const tag = app.client.$('#tag');
tag.waitForExist('#tag', 2000);
tag.moveToObject('#tag', 10, 10);
tag.rightClick('#tag', 10, 10);
// Timeout is required for context menu to appear
setTimeout(() => {
robot.setKeyboardDelay(500);
robot.keyTap('down');
robot.keyTap('down');
robot.keyTap('enter');
done();
}, 2000);
} else {
const tag = app.client.$('#tag');
tag.waitForExist('#tag', 2000);
tag.moveToObject('#tag', 10, 10);
tag.rightClick('#tag', 10, 10);
// Timeout is required for context menu to appear
setTimeout(() => {
robot.setKeyboardDelay(500);
robot.keyTap('down');
robot.keyTap('down');
robot.keyTap('enter');
done();
}, 2000);
}
it('SpellChecker should be working', async (done) => {
try {
if (await windowsActions.isAppRunning()) {
let misspelledWord = "comming ";
await webActions.navigateURL('file:///' + path.join(__dirname, '..', '..', 'demo/index.html'));
if (isWindowsOS) {
await windowsActions.bringToFront("Symphony");
await windowsActions.pressF11();
}
await webActions.inputText(ui.TAG_TEXTBOX, misspelledWord);
await webActions.openContextMenu(ui.TAG_TEXTBOX);
await webActions.selectItemOnContextMenu(3);
await webActions.verifySpellCheckerWorking(ui.TAG_TEXTBOX, misspelledWord)
}
done();
} catch (err) {
done.fail(new Error(`Fail to verify spellChecker: ${err}`));
};
});
it('should verify the text field', () => {
return app.client
.windowByIndex(0)
.getValue('#tag').then((value) => {
expect(value !== 'comming').toBeTruthy();
});
});
});
});