#1976 Implementar Puppeteer client module + core changes
gitea/salix/puppeteer There was a failure building this commit Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-01-14 09:20:14 +01:00
parent cb2f94cdaf
commit 3bcaaddb14
20 changed files with 159 additions and 158 deletions

View File

@ -1,8 +1,6 @@
/* eslint no-invalid-this: "off" */
import {url as defaultURL} from './config';
let currentUser;
let actions = {
clickIfExists: async function(selector) {
let exists;
@ -49,14 +47,6 @@ let actions = {
},
login: async function(userName) {
if (currentUser !== userName) {
let userPanelOpen = await this.evaluate(() => {
return document.querySelector('.user-popover');
});
if (!userPanelOpen)
await this.clickIfExists('#user');
await this.clickIfExists('#logout');
try {
await this.waitForURL('#!/login');
} catch (e) {
@ -68,15 +58,6 @@ let actions = {
return document.location.hash === '#!/';
}, {});
await this.changeLanguageToEnglish();
currentUser = userName;
} else {
await this.wait(() => {
return document.location.hash === '#!/';
}, {});
await this.changeLanguageToEnglish();
await this.waitToClick('a[ui-sref=home]');
}
},
selectModule: async function(moduleName) {
@ -129,7 +110,7 @@ let actions = {
let field = await this.evaluate(selector => {
return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field;
}, selector);
if (field && field.lenght) {
if ((field != null && field != '') || field == '0') {
let coords = await this.evaluate(selector => {
let rect = document.querySelector(selector).getBoundingClientRect();
return {x: rect.x + (rect.width / 2), y: rect.y + (rect.height / 2), width: rect.width};
@ -371,7 +352,7 @@ let actions = {
await this.write(`.vn-drop-down.shown`, searchValue);
await this.waitFor(100); // ul to repaint
await this.waitToClick(`.vn-drop-down.shown li.active`);
await this.waitFor(100); // input to asign value
await this.waitFor(200); // input to asign value
await this.wait((autocompleteSelector, searchValue) => {
return document.querySelector(`${autocompleteSelector} input`).value
.toLowerCase()
@ -454,6 +435,15 @@ let actions = {
transition.addEventListener('transitionend', onEnd);
});
}, selector);
},
waitForContentLoaded: async function() {
await this.evaluate(() => {
return new Promise(resolve => {
const $rootScope = angular.element(document.body).injector().get('$rootScope');
$rootScope.$on('$viewContentLoaded', resolve());
});
});
}
};

View File

@ -3,36 +3,24 @@ import Puppeteer from 'puppeteer';
import {extendPage} from './extensions';
import {url as defaultURL} from './config';
let browser;
export function getBrowser() {
return browser || {close: () => {}};
}
async function openPage(url = defaultURL) {
if (!browser) {
browser = await Puppeteer.launch({
export async function getBrowser() {
const browser = await Puppeteer.launch({
args: [
'--start-maximized'
// '--start-maximized'
// '--start-fullscreen'
// '--proxy-server="direct://"',
// '--proxy-bypass-list=*'
`--window-size=${ 1920 },${ 1080 }`,
],
defaultViewport: null,
headless: false,
slowMo: 0, // slow down by ms
});
}
const page = await browser.newPage();
let page = (await browser.pages())[0];
page = extendPage(page);
await page.setDefaultTimeout(5000);
await page.goto(url, {waitUntil: 'networkidle0'});
page.on('console', msg => {
let type = msg.type();
if (type === 'error')
console[type](msg.text());
});
const extendedPage = extendPage(page);
return extendedPage;
await page.goto(defaultURL, {waitUntil: 'networkidle0'});
return {page, close: browser.close.bind(browser)};
}
export default openPage;
export default getBrowser;

View File

@ -1,13 +1,15 @@
import openPage from '../../helpers/puppeteer';
import getBrowser from '../../helpers/puppeteer';
describe('Login path', async() => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
});
afterAll(async() => {
page.close();
await browser.close();
});
it('should receive an error when the username is incorrect', async() => {

View File

@ -1,15 +1,17 @@
import selectors from '../../helpers/selectors';
import openPage from '../../helpers/puppeteer';
import getBrowser from '../../helpers/puppeteer';
describe('Client create path', async() => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
});
afterAll(async() => {
page.close();
await browser.close();
});
it(`should search for the user Carol Danvers to confirm it isn't created yet`, async() => {
@ -55,6 +57,7 @@ describe('Client create path', async() => {
await page.autocompleteSearch(selectors.createClientView.province, 'Province one');
await page.write(selectors.createClientView.city, 'Valencia');
await page.write(selectors.createClientView.postcode, '46000');
await page.clearInput(selectors.createClientView.email);
await page.write(selectors.createClientView.email, 'incorrect email format');
await page.waitToClick(selectors.createClientView.createButton);

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Edit basicData path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Bruce Wayne');
await page.accessToSection('client.card.basicData');
});
afterAll(async() => {
page.close();
await browser.close();
});
describe('as employee', () => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Edit fiscalData path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Bruce Banner');
await page.accessToSection('client.card.address.index');
});
afterAll(async() => {
page.close();
await browser.close();
});
describe('as employee', () => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Edit billing data path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('administrative', 'client');
await page.accessToSearchResult('Bruce Banner');
await page.accessToSection('client.card.billingData');
});
afterAll(async() => {
page.close();
await browser.close();
});
it(`should attempt to edit the billing data without an IBAN but fail`, async() => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Add address path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Bruce Banner');
await page.accessToSection('client.card.address.index');
});
afterAll(async() => {
page.close();
browser.close();
});
it(`should click on the add new address button to access to the new address form`, async() => {
@ -24,11 +26,8 @@ describe('Client Add address path', () => {
it('should receive an error after clicking save button as consignee, street and town fields are empty', async() => {
await page.waitToClick(selectors.clientAddresses.defaultCheckboxInput);
await page.clearInput(selectors.clientAddresses.streetAddressInput);
await page.autocompleteSearch(selectors.clientAddresses.provinceAutocomplete, 'Province one');
await page.clearInput(selectors.clientAddresses.cityInput);
await page.write(selectors.clientAddresses.cityInput, 'Valencia');
await page.clearInput(selectors.clientAddresses.postcodeInput);
await page.write(selectors.clientAddresses.postcodeInput, '46000');
await page.autocompleteSearch(selectors.clientAddresses.agencyAutocomplete, 'Entanglement');
await page.write(selectors.clientAddresses.phoneInput, '999887744');
@ -39,25 +38,6 @@ describe('Client Add address path', () => {
expect(result).toEqual('Some fields are invalid');
});
it('should confirm the postcode have been edited', async() => {
const result = await page.waitToGetProperty(`${selectors.clientAddresses.postcodeInput} input`, 'value');
expect(result).toContain('46000');
});
it('should confirm the city have been autocompleted', async() => {
const result = await page.waitToGetProperty(`${selectors.clientAddresses.cityInput} input`, 'value');
expect(result).toEqual('Valencia');
});
it(`should confirm the province have been autocompleted`, async() => {
const result = await page.waitToGetProperty(`${selectors.clientAddresses.provinceAutocomplete} input`, 'value');
expect(result).toEqual('Province one');
});
it(`should create a new address with all it's data`, async() => {
await page.write(selectors.clientAddresses.consigneeInput, 'Bruce Bunner');
await page.write(selectors.clientAddresses.streetAddressInput, '320 Park Avenue New York');
@ -67,14 +47,20 @@ describe('Client Add address path', () => {
expect(result).toEqual('Data saved!');
});
it(`should click on the addresses button confirm the new address exists and it's the default one`, async() => {
it(`should click on the first address button to confirm the new address exists and it's the default one`, async() => {
const result = await page.waitToGetProperty(selectors.clientAddresses.defaultAddress, 'innerText');
expect(result).toContain('320 Park Avenue New York');
});
it(`should click on the make default icon of the second address then confirm it is the default one now`, async() => {
it(`should click on the make default icon of the second address`, async() => {
await page.waitToClick(selectors.clientAddresses.secondMakeDefaultStar);
const result = await page.waitForLastSnackbar();
expect(result).toEqual('Data saved!');
});
it(`should confirm the default address is the expected one`, async() => {
await page.waitForTextInElement(selectors.clientAddresses.defaultAddress, 'Somewhere in Thailand');
const result = await page.waitToGetProperty(selectors.clientAddresses.defaultAddress, 'innerText');
@ -100,9 +86,11 @@ describe('Client Add address path', () => {
});
it(`should go back to the addreses section by clicking the cancel button`, async() => {
await page.waitToClick(selectors.clientAddresses.cancelEditAddressButton);
await page.waitToClick('.vn-confirm.shown button[response="accept"]');
await page.waitForURL('address/index');
page.waitToClick(selectors.clientAddresses.cancelEditAddressButton);
await Promise.all([
page.waitForNavigation({waitUntil: ['load', 'networkidle0', 'domcontentloaded']}),
page.waitToClick('.vn-confirm.shown button[response="accept"]')
]);
const url = await page.parsedUrl();
expect(url.hash).toContain('address/index');

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client add address notes path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Petter Parker');
await page.accessToSection('client.card.address.index');
});
afterAll(async() => {
page.close();
browser.close();
});
it(`should click on the edit icon of the default address`, async() => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Edit web access path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Bruce Banner');
await page.accessToSection('client.card.webAccess');
});
afterAll(async() => {
page.close();
browser.close();
});
it(`should uncheck the Enable web access checkbox and update the name`, async() => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Add notes path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Bruce Banner');
await page.accessToSection('client.card.note.index');
});
afterAll(async() => {
page.close();
browser.close();
});
it(`should click on the add note button`, async() => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Add credit path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('salesAssistant', 'client');
await page.accessToSearchResult('Hank Pym');
await page.accessToSection('client.card.credit.index');
});
afterAll(async() => {
page.close();
browser.close();
});
it(`should click on the add credit button`, async() => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client Add greuge path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('salesAssistant', 'client');
await page.accessToSearchResult('Petter Parker');
await page.accessToSection('client.card.greuge.index');
});
afterAll(async() => {
page.close();
browser.close();
});
it(`should click on the add greuge button`, async() => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client mandate path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('salesPerson', 'client');
await page.accessToSearchResult('Petter Parker');
await page.accessToSection('client.card.mandate');
});
afterAll(async() => {
page.close();
browser.close();
});
it('should confirm the client has a mandate of the CORE type', async() => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client lock verified data path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('salesPerson', 'client');
await page.accessToSearchResult('Hank Pym');
await page.accessToSection('client.card.fiscalData');
});
afterAll(async() => {
page.close();
browser.close();
});
describe('as salesPerson', () => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client log path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('DavidCharlesHaller');
await page.accessToSection('client.card.basicData');
});
afterAll(async() => {
page.close();
browser.close();
});
it('should update the clients name', async() => {

View File

@ -1,16 +1,18 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client balance path', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('administrative', 'client');
await page.accessToSearchResult('Petter Parker');
}, 30000);
afterAll(async() => {
page.close();
browser.close();
});
it('should now edit the local user config data', async() => {

View File

@ -1,14 +1,16 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('User config', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
});
afterAll(async() => {
page.close();
browser.close();
});
describe('as salesPerson', () => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client web Payment', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('employee', 'client');
await page.accessToSearchResult('Tony Stark');
await page.accessToSection('client.card.webPayment');
});
afterAll(async() => {
page.close();
browser.close();
});
describe('as employee', () => {

View File

@ -1,17 +1,19 @@
import selectors from '../../helpers/selectors.js';
import openPage from '../../helpers/puppeteer';
import selectors from '../../helpers/selectors';
import getBrowser from '../../helpers/puppeteer';
describe('Client DMS', () => {
let browser;
let page;
beforeAll(async() => {
page = await openPage();
browser = await getBrowser();
page = browser.page;
await page.loginAndModule('salesPerson', 'client');
await page.accessToSearchResult('Tony Stark');
await page.accessToSection('client.card.dms.index');
});
afterAll(async() => {
page.close();
browser.close();
});
describe('as salesPerson', () => {