2018-10-25 14:44:03 +00:00
|
|
|
/* eslint no-invalid-this: "off" */
|
|
|
|
|
2017-09-15 10:24:37 +00:00
|
|
|
import Nightmare from 'nightmare';
|
2018-02-20 09:00:19 +00:00
|
|
|
import {URL} from 'url';
|
2019-01-26 12:12:18 +00:00
|
|
|
import config from './config.js';
|
2017-09-15 10:24:37 +00:00
|
|
|
|
2019-01-26 12:12:18 +00:00
|
|
|
let currentUser;
|
2017-10-31 07:14:33 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
let actions = {
|
2019-10-15 14:19:35 +00:00
|
|
|
clickIfExists: async function(selector) {
|
|
|
|
let exists = await this.exists(selector);
|
|
|
|
if (exists) await this.click(selector);
|
2019-10-16 07:54:02 +00:00
|
|
|
return exists;
|
2019-10-15 14:19:35 +00:00
|
|
|
},
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
parsedUrl: async function() {
|
|
|
|
return new URL(await this.url());
|
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitUntilNotPresent: async function(selector) {
|
|
|
|
await this.wait(selector => {
|
|
|
|
return document.querySelector(selector) == null;
|
|
|
|
}, selector);
|
|
|
|
},
|
|
|
|
|
2019-10-15 14:19:35 +00:00
|
|
|
changeLanguageToEnglish: async function() {
|
|
|
|
let langSelector = '.user-popover vn-autocomplete[ng-model="$ctrl.lang"]';
|
|
|
|
|
|
|
|
let lang = await this.waitToClick('#user')
|
|
|
|
.wait(langSelector)
|
|
|
|
.waitToGetProperty(`${langSelector} input`, 'value');
|
|
|
|
|
|
|
|
if (lang !== 'English')
|
|
|
|
await this.autocompleteSearch(langSelector, 'English');
|
|
|
|
},
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
doLogin: async function(userName, password) {
|
|
|
|
if (password == null) password = 'nightmare';
|
|
|
|
await this.wait(`vn-login [name=user]`)
|
|
|
|
.clearInput(`vn-login [name=user]`)
|
|
|
|
.write(`vn-login [name=user]`, userName)
|
|
|
|
.write(`vn-login [name=password]`, password)
|
|
|
|
.click(`vn-login button[type=submit]`);
|
|
|
|
},
|
|
|
|
|
2019-10-15 14:19:35 +00:00
|
|
|
login: async function(userName) {
|
|
|
|
if (currentUser !== userName) {
|
2019-10-16 07:54:02 +00:00
|
|
|
let logoutClicked = await this.clickIfExists('#logout');
|
|
|
|
|
|
|
|
if (logoutClicked) {
|
2019-10-30 15:57:14 +00:00
|
|
|
let buttonSelector = '.vn-dialog.shown button[response=accept]';
|
2019-10-28 18:52:54 +00:00
|
|
|
await this.wait(buttonSelector => {
|
2019-10-16 07:54:02 +00:00
|
|
|
return document.querySelector(buttonSelector) != null
|
|
|
|
|| location.hash == '#!/login';
|
|
|
|
}, buttonSelector);
|
|
|
|
await this.clickIfExists(buttonSelector);
|
|
|
|
}
|
2019-10-15 14:19:35 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await this.waitForURL('#!/login');
|
|
|
|
} catch (e) {
|
2019-10-28 18:52:54 +00:00
|
|
|
await this.goto(`${config.url}/#!/login`);
|
2019-10-15 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
await this.doLogin(userName, null)
|
2019-10-15 14:19:35 +00:00
|
|
|
.waitForURL('#!/')
|
|
|
|
.changeLanguageToEnglish();
|
|
|
|
|
|
|
|
currentUser = userName;
|
|
|
|
} else
|
2019-11-10 13:13:55 +00:00
|
|
|
await this.waitToClick('a[ui-sref=home]');
|
2019-10-15 14:19:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
waitForLogin: async function(userName) {
|
|
|
|
await this.login(userName);
|
|
|
|
},
|
|
|
|
|
|
|
|
selectModule: async function(moduleName) {
|
|
|
|
let snakeName = moduleName.replace(/[\w]([A-Z])/g, m => {
|
|
|
|
return m[0] + '-' + m[1];
|
|
|
|
}).toLowerCase();
|
|
|
|
|
|
|
|
await this.waitToClick(`vn-home a[ui-sref="${moduleName}.index"]`)
|
|
|
|
.waitForURL(snakeName);
|
|
|
|
},
|
|
|
|
|
|
|
|
loginAndModule: async function(userName, moduleName) {
|
|
|
|
await this.login(userName)
|
|
|
|
.selectModule(moduleName);
|
|
|
|
},
|
|
|
|
|
|
|
|
datePicker: async function(selector, changeMonth, day) {
|
|
|
|
let date = new Date();
|
|
|
|
if (changeMonth) date.setMonth(date.getMonth() + changeMonth);
|
|
|
|
date.setDate(day ? day : 16);
|
|
|
|
date = date.toISOString().substr(0, 10);
|
|
|
|
|
|
|
|
await this.wait(selector)
|
|
|
|
.evaluate((selector, date) => {
|
|
|
|
let input = document.querySelector(selector).$ctrl.input;
|
|
|
|
input.value = date;
|
|
|
|
input.dispatchEvent(new Event('change'));
|
|
|
|
}, selector, date);
|
|
|
|
},
|
|
|
|
|
|
|
|
pickTime: async function(selector, time) {
|
|
|
|
await this.wait(selector)
|
|
|
|
.evaluate((selector, time) => {
|
2019-10-16 07:54:02 +00:00
|
|
|
let input = document.querySelector(selector).$ctrl.input;
|
2019-10-15 14:19:35 +00:00
|
|
|
input.value = time;
|
|
|
|
input.dispatchEvent(new Event('change'));
|
|
|
|
}, selector, time);
|
2019-10-18 19:36:30 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
clearTextarea: function(selector) {
|
|
|
|
return this.wait(selector)
|
2019-05-03 15:49:38 +00:00
|
|
|
.evaluate(inputSelector => {
|
|
|
|
return document.querySelector(inputSelector).value = '';
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector);
|
2019-05-03 15:49:38 +00:00
|
|
|
},
|
2018-10-31 10:58:10 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
clearInput: function(selector) {
|
|
|
|
return this.wait(selector)
|
2019-10-08 21:57:02 +00:00
|
|
|
.evaluate(selector => {
|
2019-10-09 22:47:29 +00:00
|
|
|
let $ctrl = document.querySelector(selector).closest('.vn-field').$ctrl;
|
|
|
|
$ctrl.field = null;
|
|
|
|
$ctrl.$.$apply();
|
2019-10-08 21:57:02 +00:00
|
|
|
$ctrl.input.dispatchEvent(new Event('change'));
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector);
|
2019-05-03 15:49:38 +00:00
|
|
|
},
|
2017-09-15 10:24:37 +00:00
|
|
|
|
2019-10-28 18:52:54 +00:00
|
|
|
getProperty: function(selector, property) {
|
|
|
|
return this.evaluate((selector, property) => {
|
2018-11-22 11:34:20 +00:00
|
|
|
return document.querySelector(selector)[property].replace(/\s+/g, ' ').trim();
|
2019-10-28 18:52:54 +00:00
|
|
|
}, selector, property);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitPropertyLength: function(selector, property, minLength) {
|
|
|
|
return this.wait((selector, property, minLength) => {
|
2018-11-22 11:34:20 +00:00
|
|
|
const element = document.querySelector(selector);
|
|
|
|
return element && element[property] != null && element[property] !== '' && element[property].length >= minLength;
|
|
|
|
}, selector, property, minLength)
|
2019-10-28 16:31:33 +00:00
|
|
|
.getProperty(selector, property);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitPropertyValue: function(selector, property, status) {
|
|
|
|
return this.wait(selector)
|
2019-02-07 13:33:52 +00:00
|
|
|
.wait((selector, property, status) => {
|
|
|
|
const element = document.querySelector(selector);
|
|
|
|
return element[property] === status;
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector, property, status);
|
2019-02-07 13:33:52 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitToGetProperty: function(selector, property) {
|
|
|
|
return this.wait((selector, property) => {
|
2018-11-22 11:34:20 +00:00
|
|
|
const element = document.querySelector(selector);
|
2019-07-01 11:41:38 +00:00
|
|
|
|
2018-11-22 11:34:20 +00:00
|
|
|
return element && element[property] != null && element[property] !== '';
|
|
|
|
}, selector, property)
|
2019-10-28 16:31:33 +00:00
|
|
|
.getProperty(selector, property);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
write: function(selector, text) {
|
|
|
|
return this.wait(selector)
|
|
|
|
.type(selector, text);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
2017-09-15 10:24:37 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitToClick: function(selector) {
|
|
|
|
return this.wait(selector)
|
|
|
|
.click(selector);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 18:52:54 +00:00
|
|
|
focusElement: function(selector) {
|
|
|
|
return this.wait(selector)
|
|
|
|
.evaluate(selector => {
|
2019-10-08 21:57:02 +00:00
|
|
|
let element = document.querySelector(selector);
|
2019-02-26 16:32:32 +00:00
|
|
|
element.focus();
|
2019-10-28 18:52:54 +00:00
|
|
|
}, selector);
|
2019-02-26 16:32:32 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 18:52:54 +00:00
|
|
|
isVisible: function(selector) {
|
|
|
|
return this.wait(selector)
|
|
|
|
.evaluate(elementSelector => {
|
2018-11-22 11:34:20 +00:00
|
|
|
const selectorMatches = document.querySelectorAll(elementSelector);
|
|
|
|
const element = selectorMatches[0];
|
2019-09-30 09:30:54 +00:00
|
|
|
|
2018-11-22 11:34:20 +00:00
|
|
|
if (selectorMatches.length > 1)
|
|
|
|
throw new Error(`multiple matches of ${elementSelector} found`);
|
|
|
|
|
|
|
|
let isVisible = false;
|
|
|
|
if (element) {
|
|
|
|
const eventHandler = event => {
|
|
|
|
event.preventDefault();
|
|
|
|
isVisible = true;
|
|
|
|
};
|
|
|
|
element.addEventListener('mouseover', eventHandler);
|
2019-09-30 09:30:54 +00:00
|
|
|
const rect = element.getBoundingClientRect();
|
|
|
|
const x = rect.left + rect.width / 2;
|
|
|
|
const y = rect.top + rect.height / 2;
|
2018-11-22 11:34:20 +00:00
|
|
|
const elementInCenter = document.elementFromPoint(x, y);
|
2019-09-30 09:30:54 +00:00
|
|
|
const elementInTopLeft = document.elementFromPoint(rect.left, rect.top);
|
|
|
|
const elementInBottomRight = document.elementFromPoint(rect.right, rect.bottom);
|
2018-11-22 11:34:20 +00:00
|
|
|
const e = new MouseEvent('mouseover', {
|
|
|
|
view: window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
|
|
|
});
|
2019-09-30 09:30:54 +00:00
|
|
|
|
2018-11-22 11:34:20 +00:00
|
|
|
if (elementInCenter)
|
|
|
|
elementInCenter.dispatchEvent(e);
|
|
|
|
|
|
|
|
if (elementInTopLeft)
|
|
|
|
elementInTopLeft.dispatchEvent(e);
|
|
|
|
|
|
|
|
if (elementInBottomRight)
|
|
|
|
elementInBottomRight.dispatchEvent(e);
|
|
|
|
|
|
|
|
element.removeEventListener('mouseover', eventHandler);
|
|
|
|
}
|
|
|
|
return isVisible;
|
2019-10-28 18:52:54 +00:00
|
|
|
}, selector);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitImgLoad: function(selector) {
|
|
|
|
return this.wait(selector)
|
2019-02-07 08:07:00 +00:00
|
|
|
.wait(selector => {
|
|
|
|
const imageReady = document.querySelector(selector).complete;
|
|
|
|
return imageReady;
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector);
|
2019-02-07 08:07:00 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
clickIfVisible: function(selector) {
|
|
|
|
return this.wait(selector)
|
2019-02-04 13:47:55 +00:00
|
|
|
.isVisible(selector)
|
|
|
|
.then(visible => {
|
|
|
|
if (visible)
|
|
|
|
return this.click(selector);
|
|
|
|
|
|
|
|
throw new Error(`invisible selector: ${selector}`);
|
2019-10-28 16:31:33 +00:00
|
|
|
});
|
2019-02-04 13:47:55 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 18:52:54 +00:00
|
|
|
countElement: function(selector) {
|
|
|
|
return this.evaluate(selector => {
|
2018-11-22 11:34:20 +00:00
|
|
|
return document.querySelectorAll(selector).length;
|
2019-10-28 18:52:54 +00:00
|
|
|
}, selector);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForNumberOfElements: function(selector, count) {
|
|
|
|
return this.wait((selector, count) => {
|
2018-11-22 11:34:20 +00:00
|
|
|
return document.querySelectorAll(selector).length === count;
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector, count);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForClassNotPresent: function(selector, className) {
|
|
|
|
return this.wait(selector)
|
2018-11-22 11:34:20 +00:00
|
|
|
.wait((selector, className) => {
|
|
|
|
if (!document.querySelector(selector).classList.contains(className))
|
|
|
|
return true;
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector, className);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForClassPresent: function(selector, className) {
|
|
|
|
return this.wait(selector)
|
2019-06-19 12:40:47 +00:00
|
|
|
.wait((elementSelector, targetClass) => {
|
|
|
|
if (document.querySelector(elementSelector).classList.contains(targetClass))
|
2018-11-22 11:34:20 +00:00
|
|
|
return true;
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector, className);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForTextInElement: function(selector, text) {
|
|
|
|
return this.wait(selector)
|
2019-02-13 07:53:57 +00:00
|
|
|
.wait((selector, text) => {
|
|
|
|
return document.querySelector(selector).innerText.toLowerCase().includes(text.toLowerCase());
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector, text);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForTextInInput: function(selector, text) {
|
|
|
|
return this.wait(selector)
|
2019-02-07 13:33:52 +00:00
|
|
|
.wait((selector, text) => {
|
|
|
|
return document.querySelector(selector).value.toLowerCase().includes(text.toLowerCase());
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector, text);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 18:52:54 +00:00
|
|
|
waitForInnerText: function(selector) {
|
|
|
|
return this.wait(selector)
|
2018-11-22 11:34:20 +00:00
|
|
|
.wait(selector => {
|
|
|
|
const innerText = document.querySelector(selector).innerText;
|
|
|
|
return innerText != null && innerText != '';
|
|
|
|
}, selector)
|
2019-10-28 18:52:54 +00:00
|
|
|
.evaluate(selector => {
|
2018-11-22 11:34:20 +00:00
|
|
|
return document.querySelector(selector).innerText;
|
2019-10-28 18:52:54 +00:00
|
|
|
}, selector);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForEmptyInnerText: function(selector) {
|
|
|
|
return this.wait(selector => {
|
2018-11-22 11:34:20 +00:00
|
|
|
return document.querySelector(selector).innerText == '';
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
2018-09-10 08:23:26 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForURL: function(hashURL) {
|
|
|
|
return this.wait(hash => {
|
2018-11-22 11:34:20 +00:00
|
|
|
return document.location.hash.includes(hash);
|
2019-10-28 16:31:33 +00:00
|
|
|
}, hashURL);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 18:52:54 +00:00
|
|
|
waitForShapes: function(selector) {
|
|
|
|
return this.wait(selector)
|
|
|
|
.evaluate(selector => {
|
2018-11-22 11:34:20 +00:00
|
|
|
const shapes = document.querySelectorAll(selector);
|
|
|
|
const shapesList = [];
|
|
|
|
|
|
|
|
for (const shape of shapes)
|
|
|
|
shapesList.push(shape.innerText);
|
|
|
|
|
|
|
|
|
|
|
|
return shapesList;
|
2019-10-28 18:52:54 +00:00
|
|
|
}, selector);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForSnackbar: function() {
|
|
|
|
return this.wait(500)
|
|
|
|
.waitForShapes('vn-snackbar .shape .text');
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 18:52:54 +00:00
|
|
|
waitForLastShape: function(selector) {
|
|
|
|
return this.wait(selector)
|
|
|
|
.evaluate(selector => {
|
2018-11-22 11:34:20 +00:00
|
|
|
const shape = document.querySelector(selector);
|
|
|
|
|
|
|
|
return shape.innerText;
|
2019-10-28 18:52:54 +00:00
|
|
|
}, selector);
|
2018-11-22 11:34:20 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForLastSnackbar: function() {
|
|
|
|
return this.wait(500)
|
|
|
|
.waitForLastShape('vn-snackbar .shape .text');
|
2018-11-23 07:05:57 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
accessToSearchResult: function(searchValue) {
|
|
|
|
return this.clearInput('vn-searchbar input')
|
2019-05-03 15:49:38 +00:00
|
|
|
.write('vn-searchbar input', searchValue)
|
|
|
|
.click('vn-searchbar vn-icon[icon="search"]')
|
2019-03-01 10:08:31 +00:00
|
|
|
.wait(100)
|
2019-11-10 10:08:44 +00:00
|
|
|
.waitForNumberOfElements('.search-result', 1)
|
2018-12-02 23:45:34 +00:00
|
|
|
.evaluate(() => {
|
|
|
|
return document.querySelector('ui-view vn-card vn-table') != null;
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
if (result)
|
|
|
|
return this.waitToClick('ui-view vn-card vn-td');
|
|
|
|
|
|
|
|
return this.waitToClick('ui-view vn-card a');
|
2019-10-28 16:31:33 +00:00
|
|
|
});
|
2018-12-02 23:45:34 +00:00
|
|
|
},
|
2018-11-23 07:05:57 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
accessToSection: function(sectionRoute) {
|
|
|
|
return this.wait(`vn-left-menu`)
|
2018-12-02 23:45:34 +00:00
|
|
|
.evaluate(sectionRoute => {
|
|
|
|
return document.querySelector(`vn-left-menu ul li ul li > a[ui-sref="${sectionRoute}"]`) != null;
|
|
|
|
}, sectionRoute)
|
|
|
|
.then(nested => {
|
|
|
|
if (!nested)
|
|
|
|
return this.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`);
|
|
|
|
|
2019-11-10 13:13:55 +00:00
|
|
|
return this.waitToClick('vn-left-menu vn-item-section > vn-icon[icon=keyboard_arrow_down]')
|
2018-12-02 23:45:34 +00:00
|
|
|
.wait('vn-left-menu .expanded')
|
|
|
|
.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`);
|
2019-10-28 16:31:33 +00:00
|
|
|
});
|
2019-01-07 08:33:07 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
autocompleteSearch: function(autocompleteSelector, searchValue) {
|
|
|
|
return this.waitToClick(`${autocompleteSelector} input`)
|
|
|
|
.write(`.vn-drop-down.shown input`, searchValue)
|
|
|
|
.waitToClick(`.vn-drop-down.shown li.active`)
|
2019-01-07 08:33:07 +00:00
|
|
|
.wait((autocompleteSelector, searchValue) => {
|
2019-09-30 09:30:54 +00:00
|
|
|
return document.querySelector(`${autocompleteSelector} input`).value
|
|
|
|
.toLowerCase()
|
|
|
|
.includes(searchValue.toLowerCase());
|
2019-10-28 16:31:33 +00:00
|
|
|
}, autocompleteSelector, searchValue);
|
2019-01-16 07:52:56 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
reloadSection: function(sectionRoute) {
|
|
|
|
return this.waitToClick('vn-icon[icon="desktop_windows"]')
|
2019-01-27 19:49:15 +00:00
|
|
|
.wait('vn-card.summary')
|
2019-10-28 16:31:33 +00:00
|
|
|
.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`);
|
2019-01-30 10:09:53 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
forceReloadSection: function(sectionRoute) {
|
|
|
|
return this.waitToClick('vn-icon[icon="desktop_windows"]')
|
2019-10-30 15:57:14 +00:00
|
|
|
.waitToClick('button[response="accept"]')
|
2019-01-30 10:09:53 +00:00
|
|
|
.wait('vn-card.summary')
|
2019-10-28 16:31:33 +00:00
|
|
|
.waitToClick(`vn-left-menu li > a[ui-sref="${sectionRoute}"]`);
|
2019-02-14 19:17:22 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
checkboxState: function(selector) {
|
|
|
|
return this.wait(selector)
|
2019-09-30 18:46:22 +00:00
|
|
|
.evaluate(selector => {
|
|
|
|
let checkbox = document.querySelector(selector);
|
|
|
|
switch (checkbox.$ctrl.field) {
|
|
|
|
case null:
|
|
|
|
return 'intermediate';
|
|
|
|
case true:
|
|
|
|
return 'checked';
|
|
|
|
default:
|
|
|
|
return 'unchecked';
|
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector);
|
2019-09-30 18:46:22 +00:00
|
|
|
},
|
2019-02-14 19:17:22 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
isDisabled: function(selector) {
|
|
|
|
return this.wait(selector)
|
2019-09-30 18:46:22 +00:00
|
|
|
.evaluate(selector => {
|
|
|
|
let element = document.querySelector(selector);
|
|
|
|
return element.$ctrl.disabled;
|
2019-10-28 16:31:33 +00:00
|
|
|
}, selector);
|
2019-06-27 13:33:15 +00:00
|
|
|
},
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
waitForSpinnerLoad: function() {
|
2019-11-10 13:13:55 +00:00
|
|
|
return this.waitUntilNotPresent('vn-topbar vn-spinner');
|
2019-06-27 13:33:15 +00:00
|
|
|
},
|
2018-11-22 11:34:20 +00:00
|
|
|
};
|
2018-09-10 08:23:26 +00:00
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
for (let name in actions) {
|
2019-10-15 14:19:35 +00:00
|
|
|
Nightmare.action(name, function(...args) {
|
2019-10-28 18:52:54 +00:00
|
|
|
let fnArgs = args.slice(0, args.length - 1);
|
2019-10-15 14:19:35 +00:00
|
|
|
let done = args[args.length - 1];
|
2019-10-28 18:52:54 +00:00
|
|
|
|
|
|
|
actions[name].apply(this, fnArgs)
|
|
|
|
.then(res => done(null, res))
|
|
|
|
.catch(err => {
|
|
|
|
let stringArgs = fnArgs
|
|
|
|
.map(i => typeof i == 'function' ? 'Function' : i)
|
|
|
|
.join(', ');
|
|
|
|
|
|
|
|
let orgMessage = err.message.startsWith('.wait()')
|
|
|
|
? '.wait() timed out'
|
|
|
|
: err.message;
|
|
|
|
|
|
|
|
done(new Error(`.${name}(${stringArgs}) failed: ${orgMessage}`));
|
|
|
|
});
|
2019-10-15 14:19:35 +00:00
|
|
|
});
|
|
|
|
}
|