#1976 Implementar Puppeteer autocompleteSearch fix
gitea/salix/puppeteer There was a failure building this commit Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-01-16 13:40:51 +01:00
parent 7cb1626620
commit 584212a659
22 changed files with 92 additions and 75 deletions

View File

@ -116,9 +116,12 @@ let actions = {
return {x: rect.x + (rect.width / 2), y: rect.y + (rect.height / 2), width: rect.width}; return {x: rect.x + (rect.width / 2), y: rect.y + (rect.height / 2), width: rect.width};
}, selector); }, selector);
await this.mouse.move(coords.x, coords.y); await this.mouse.move(coords.x, coords.y);
await this.waitFor(1000); await this.waitForSelector(`${selector} [icon="clear"]`, {visible: true});
await this.waitToClick(`${selector} [icon="clear"]`); await this.waitToClick(`${selector} [icon="clear"]`);
} }
await this.evaluate(selector => {
return document.querySelector(`${selector} input`).closest('.vn-field').$ctrl.field == '';
}, selector);
}, },
getProperty: async function(selector, property) { getProperty: async function(selector, property) {
@ -153,8 +156,9 @@ let actions = {
}, },
write: async function(selector, text) { write: async function(selector, text) {
await this.wait(selector, {}); await this.waitForSelector(selector, {});
await this.type(`${selector} input`, text); await this.type(`${selector} input`, text);
await this.waitForTextInInput(selector, text);
}, },
waitToClick: async function(selector) { waitToClick: async function(selector) {
@ -292,7 +296,7 @@ let actions = {
}, },
waitForURL: async function(hashURL) { waitForURL: async function(hashURL) {
await this.wait(expectedHash => { await this.waitForFunction(expectedHash => {
return document.location.hash.includes(expectedHash); return document.location.hash.includes(expectedHash);
}, {}, hashURL); }, {}, hashURL);
}, },
@ -344,23 +348,34 @@ let actions = {
navButton.scrollIntoViewIfNeeded(); navButton.scrollIntoViewIfNeeded();
return navButton.click(); return navButton.click();
}, sectionRoute); }, sectionRoute);
await this.waitForNavigation({waitUntil: ['networkidle0']});
}, },
autocompleteSearch: async function(autocompleteSelector, searchValue) { autocompleteSearch: async function(selector, searchValue) {
await this.waitFor(100); // time in which the autocomplete data loads try {
await this.waitToClick(`${autocompleteSelector} input`); await this.waitToClick(`${selector} input`),
await this.write(`.vn-drop-down.shown`, searchValue); await this.waitForSelector(selector => {
await this.waitFor(100); // ul to repaint document
await this.waitToClick(`.vn-drop-down.shown li.active`); .querySelector(`${selector} vn-drop-down`).$ctrl.content
await this.waitFor(200); // input to asign value .querySelectorAll('li');
await this.wait((autocompleteSelector, searchValue) => { }, selector);
return document.querySelector(`${autocompleteSelector} input`).value
.toLowerCase() await this.write(`.vn-drop-down.shown`, searchValue),
await this.waitForFunction(selector => {
return document
.querySelector(`${selector} vn-drop-down`).$ctrl.content
.querySelector('li.active');
}, {}, selector);
await this.keyboard.press('Enter');
await this.waitForFunction((selector, searchValue) => {
return document.querySelector(`${selector} input`).value.toLowerCase()
.includes(searchValue.toLowerCase()); .includes(searchValue.toLowerCase());
}, {}, autocompleteSelector, searchValue); }, {}, selector, searchValue);
await this.wait(() => { } catch (error) {
return !document.querySelector('.vn-drop-down'); throw new Error(`${selector} failed to autocomplete ${searchValue}! ${error}`);
}, {}); }
await this.waitForMutation(`.vn-drop-down`, 'childList');
}, },
reloadSection: async function(sectionRoute) { reloadSection: async function(sectionRoute) {
@ -424,6 +439,29 @@ let actions = {
await this.waitForSpinnerLoad(); await this.waitForSpinnerLoad();
}, },
waitForMutation: async function(selector, type) {
try {
await this.evaluate((selector, type) => {
return new Promise(resolve => {
const config = {attributes: true, childList: true, subtree: true};
const target = document.querySelector(selector);
const onEnd = function(mutationsList, observer) {
resolve();
observer.disconnect();
};
const observer = new MutationObserver(onEnd);
observer.expectedType = type;
observer.observe(target, config);
});
}, selector, type);
} catch (error) {
throw new Error(`failed to wait for mutation type: ${type}`);
}
},
waitForTransitionEnd: async function(selector) { waitForTransitionEnd: async function(selector) {
await this.evaluate(selector => { await this.evaluate(selector => {
return new Promise(resolve => { return new Promise(resolve => {

View File

@ -6,10 +6,6 @@ import {url as defaultURL} from './config';
export async function getBrowser() { export async function getBrowser() {
const browser = await Puppeteer.launch({ const browser = await Puppeteer.launch({
args: [ args: [
// '--start-maximized'
// '--start-fullscreen'
// '--proxy-server="direct://"',
// '--proxy-bypass-list=*'
`--window-size=${ 1920 },${ 1080 }`, `--window-size=${ 1920 },${ 1080 }`,
], ],
defaultViewport: null, defaultViewport: null,

View File

@ -57,7 +57,6 @@ describe('Client create path', async() => {
await page.autocompleteSearch(selectors.createClientView.province, 'Province one'); await page.autocompleteSearch(selectors.createClientView.province, 'Province one');
await page.write(selectors.createClientView.city, 'Valencia'); await page.write(selectors.createClientView.city, 'Valencia');
await page.write(selectors.createClientView.postcode, '46000'); await page.write(selectors.createClientView.postcode, '46000');
await page.clearInput(selectors.createClientView.email); await page.clearInput(selectors.createClientView.email);
await page.write(selectors.createClientView.email, 'incorrect email format'); await page.write(selectors.createClientView.email, 'incorrect email format');
await page.waitToClick(selectors.createClientView.createButton); await page.waitToClick(selectors.createClientView.createButton);

View File

@ -86,11 +86,9 @@ describe('Client Add address path', () => {
}); });
it(`should go back to the addreses section by clicking the cancel button`, async() => { it(`should go back to the addreses section by clicking the cancel button`, async() => {
page.waitToClick(selectors.clientAddresses.cancelEditAddressButton); await page.waitToClick(selectors.clientAddresses.cancelEditAddressButton);
await Promise.all([ await page.waitToClick('.vn-confirm.shown button[response="accept"]');
page.waitForNavigation({waitUntil: ['load', 'networkidle0', 'domcontentloaded']}), await page.waitForURL('address/index');
page.waitToClick('.vn-confirm.shown button[response="accept"]')
]);
const url = await page.parsedUrl(); const url = await page.parsedUrl();
expect(url.hash).toContain('address/index'); expect(url.hash).toContain('address/index');

View File

@ -128,7 +128,6 @@ describe('Client lock verified data path', () => {
it('should now edit the social name', async() => { it('should now edit the social name', async() => {
await page.clearInput(selectors.clientFiscalData.socialNameInput); await page.clearInput(selectors.clientFiscalData.socialNameInput);
await page.waitFor(100);
await page.write(selectors.clientFiscalData.socialNameInput, 'new social name edition'); await page.write(selectors.clientFiscalData.socialNameInput, 'new social name edition');
await page.waitToClick(selectors.clientFiscalData.saveButton); await page.waitToClick(selectors.clientFiscalData.saveButton);
const result = await page.waitForLastSnackbar(); const result = await page.waitForLastSnackbar();

View File

@ -41,16 +41,18 @@ describe('Client balance path', () => {
it('should click the new payment button', async() => { it('should click the new payment button', async() => {
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
await page.reloadSection('client.card.balance.index'); await page.reloadSection('client.card.balance.index');
await page.waitFor(1000);
await page.waitToClick(selectors.clientBalance.newPaymentButton);
await page.waitForURL('/balance'); await page.waitForURL('/balance');
let url = await page.parsedUrl(); let url = await page.parsedUrl();
expect(url.hash).toContain('/balance'); expect(url.hash).toContain('/balance');
}); });
it('should create a new payment that clears the debt', async() => { it('should create a new payment that clears the debt', async() => {
await page.waitFor(1000); await Promise.all([
page.waitToClick(selectors.clientBalance.newPaymentButton),
page.waitForSelector('.vn-dialog.vn-popup.shown', {visible: true})
]);
await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Pay on receipt'); await page.autocompleteSearch(selectors.clientBalance.newPaymentBank, 'Pay on receipt');
await page.waitToClick(selectors.clientBalance.saveButton); await page.waitToClick(selectors.clientBalance.saveButton);
let result = await page.waitForLastSnackbar(); let result = await page.waitForLastSnackbar();
@ -71,16 +73,9 @@ describe('Client balance path', () => {
expect(firstBalanceLine).toContain('0.00'); expect(firstBalanceLine).toContain('0.00');
}); });
it('should now click the new payment button', async() => {
await page.waitToClick(selectors.clientBalance.newPaymentButton);
await page.waitForURL('/balance');
let url = await page.parsedUrl();
expect(url.hash).toContain('/balance');
});
it('should create a new payment that sets the balance to positive value', async() => { it('should create a new payment that sets the balance to positive value', async() => {
await page.waitFor(1000); await page.waitToClick(selectors.clientBalance.newPaymentButton);
await page.waitFor(1000); // didn't manage to make this dynamic to allow clearInput to find the icon clear... :(
await page.clearInput(selectors.clientBalance.newPaymentAmountInput); await page.clearInput(selectors.clientBalance.newPaymentAmountInput);
await page.write(selectors.clientBalance.newPaymentAmountInput, '100'); await page.write(selectors.clientBalance.newPaymentAmountInput, '100');
await page.waitToClick(selectors.clientBalance.saveButton); await page.waitToClick(selectors.clientBalance.saveButton);
@ -98,7 +93,7 @@ describe('Client balance path', () => {
it('should create a new payment that sets the balance back to the original negative value', async() => { it('should create a new payment that sets the balance back to the original negative value', async() => {
await page.waitToClick(selectors.clientBalance.newPaymentButton); await page.waitToClick(selectors.clientBalance.newPaymentButton);
await page.waitFor(1000); await page.waitForSelector('.vn-dialog.vn-popup.shown', {visible: true});
await page.clearInput(selectors.clientBalance.newPaymentAmountInput); await page.clearInput(selectors.clientBalance.newPaymentAmountInput);
await page.write(selectors.clientBalance.newPaymentAmountInput, '-150'); await page.write(selectors.clientBalance.newPaymentAmountInput, '-150');
await page.waitToClick(selectors.clientBalance.saveButton); await page.waitToClick(selectors.clientBalance.saveButton);

View File

@ -389,12 +389,9 @@ describe('Worker time control path', () => {
it(`should check he didn't scan in this week yet`, async() => { it(`should check he didn't scan in this week yet`, async() => {
await page.waitToClick(selectors.workerTimeControl.navigateBackToIndex); await page.waitToClick(selectors.workerTimeControl.navigateBackToIndex);
await page.accessToSearchResult('salesBoss'); await page.accessToSearchResult('salesBoss');
await Promise.all([ await page.accessToSection('worker.card.timeControl');
page.waitForNavigation({waitUntil: ['load', 'networkidle0', 'domcontentloaded']}),
page.waitForContentLoaded(),
page.accessToSection('worker.card.timeControl')
]);
await page.waitFor(1000); await page.waitFor(1000);
const wholeWeekHours = await page const wholeWeekHours = await page
.waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText'); .waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText');

View File

@ -11,7 +11,7 @@ describe('Item summary path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it('should search for an item', async() => { it('should search for an item', async() => {

View File

@ -13,7 +13,7 @@ describe('Item Edit basic data path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it(`should check the descritor edit button is visible for buyer`, async() => { it(`should check the descritor edit button is visible for buyer`, async() => {

View File

@ -13,7 +13,7 @@ describe('Item edit tax path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it(`should add the item tax to all countries`, async() => { it(`should add the item tax to all countries`, async() => {

View File

@ -13,7 +13,7 @@ describe('Item create tags path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it(`should create a new tag and delete a former one`, async() => { it(`should create a new tag and delete a former one`, async() => {

View File

@ -13,7 +13,7 @@ describe('Item create niche path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it(`should click create a new niche and delete a former one`, async() => { it(`should click create a new niche and delete a former one`, async() => {

View File

@ -13,7 +13,7 @@ describe('Item Create botanical path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it(`should create a new botanical for the item`, async() => { it(`should create a new botanical for the item`, async() => {

View File

@ -13,7 +13,7 @@ describe('Item Create barcodes path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it(`should click create a new code and delete a former one`, async() => { it(`should click create a new code and delete a former one`, async() => {

View File

@ -11,7 +11,7 @@ describe('Item Create/Clone path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
describe('create', () => { describe('create', () => {

View File

@ -11,7 +11,7 @@ describe('Item regularize path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it('should edit the user local warehouse', async() => { it('should edit the user local warehouse', async() => {
@ -23,11 +23,13 @@ describe('Item regularize path', () => {
expect(result).toEqual('Data saved!'); expect(result).toEqual('Data saved!');
}); });
it('should open the user config form to check the local settings', async() => { it('should check the local settings were saved', async() => {
await page.waitToClick(selectors.globalItems.userMenuButton);
const userLocalWarehouse = await page const userLocalWarehouse = await page
.waitToGetProperty(`${selectors.globalItems.userLocalWarehouse} input`, 'value'); .waitToGetProperty(`${selectors.globalItems.userLocalWarehouse} input`, 'value');
await page.keyboard.press('Escape');
await page.waitForSelector('.user-popover.vn-popover', {hidden: true});
expect(userLocalWarehouse).toContain('Warehouse Four'); expect(userLocalWarehouse).toContain('Warehouse Four');
}); });
@ -60,7 +62,6 @@ describe('Item regularize path', () => {
it('should regularize the item', async() => { it('should regularize the item', async() => {
await page.write(selectors.itemDescriptor.regularizeQuantityInput, '100'); await page.write(selectors.itemDescriptor.regularizeQuantityInput, '100');
await page.wait(1000); // time for autocomplete to load
await page.autocompleteSearch(selectors.itemDescriptor.regularizeWarehouseAutocomplete, 'Warehouse One'); await page.autocompleteSearch(selectors.itemDescriptor.regularizeWarehouseAutocomplete, 'Warehouse One');
await page.waitToClick(selectors.itemDescriptor.regularizeSaveButton); await page.waitToClick(selectors.itemDescriptor.regularizeSaveButton);
const result = await page.waitForLastSnackbar(); const result = await page.waitForLastSnackbar();
@ -91,9 +92,8 @@ describe('Item regularize path', () => {
it('should search for the ticket with alias missing', async() => { it('should search for the ticket with alias missing', async() => {
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
await page.waitForTransitionEnd('.vn-popover');
await page.write(selectors.ticketsIndex.searchTicketInput, 'missing'); await page.write(selectors.ticketsIndex.searchTicketInput, 'missing');
await page.waitToClick(selectors.ticketsIndex.searchButton); await page.keyboard.press('Enter');
await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1);
const result = await page.countElement(selectors.ticketsIndex.searchResult); const result = await page.countElement(selectors.ticketsIndex.searchResult);

View File

@ -12,7 +12,7 @@ describe('Item index path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it('should click on the fields to show button to open the list of columns to show', async() => { it('should click on the fields to show button to open the list of columns to show', async() => {
@ -51,10 +51,7 @@ describe('Item index path', () => {
}); });
it('should check the ids column is not visible', async() => { it('should check the ids column is not visible', async() => {
const idVisible = await page await page.waitForSelector(selectors.itemsIndex.firstItemId, {hidden: true});
.isVisible(selectors.itemsIndex.firstItemId);
expect(idVisible).toBeFalsy();
}); });
it('should mark all unchecked boxes to leave the index as it was', async() => { it('should mark all unchecked boxes to leave the index as it was', async() => {

View File

@ -11,7 +11,7 @@ describe('Item log path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it(`should search for the Knowledge artifact to confirm it isn't created yet`, async() => { it(`should search for the Knowledge artifact to confirm it isn't created yet`, async() => {

View File

@ -13,7 +13,7 @@ describe('Item descriptor path', () => {
}); });
afterAll(async() => { afterAll(async() => {
browser.close(); await browser.close();
}); });
it('should check the descriptor inactive icon is dark as the item is active', async() => { it('should check the descriptor inactive icon is dark as the item is active', async() => {

View File

@ -59,7 +59,6 @@ xdescribe('Ticket Edit sale path', () => {
it(`should click on the zoomed image to close it`, async() => { it(`should click on the zoomed image to close it`, async() => {
const result = await nightmare const result = await nightmare
.wait(100)
.clickIfVisible(selectors.ticketSales.firstSaleZoomedImage) .clickIfVisible(selectors.ticketSales.firstSaleZoomedImage)
.countElement(selectors.ticketSales.firstSaleZoomedImage); .countElement(selectors.ticketSales.firstSaleZoomedImage);
@ -149,7 +148,6 @@ xdescribe('Ticket Edit sale path', () => {
it('should confirm the price have been updated', async() => { it('should confirm the price have been updated', async() => {
const result = await nightmare const result = await nightmare
.wait(1999)
.waitToGetProperty(`${selectors.ticketSales.firstSalePrice} span`, 'innerText'); .waitToGetProperty(`${selectors.ticketSales.firstSalePrice} span`, 'innerText');
expect(result).toContain('5.00'); expect(result).toContain('5.00');
@ -426,7 +424,7 @@ xdescribe('Ticket Edit sale path', () => {
const result = await nightmare const result = await nightmare
.waitToClick(selectors.ticketSales.moreMenu) .waitToClick(selectors.ticketSales.moreMenu)
.waitToClick(selectors.ticketSales.moreMenuUpdateDiscount) .waitToClick(selectors.ticketSales.moreMenuUpdateDiscount)
.write(selectors.ticketSales.moreMenuUpdateDiscountInput, 100) // .write(selectors.ticketSales.moreMenuUpdateDiscountInput, 100) can't find the selector on app (deleted the selector), menu option was removed?
.write('body', '\u000d') .write('body', '\u000d')
.waitForTextInElement(selectors.ticketSales.totalImport, '0.00') .waitForTextInElement(selectors.ticketSales.totalImport, '0.00')
.waitToGetProperty(selectors.ticketSales.totalImport, 'innerText'); .waitToGetProperty(selectors.ticketSales.totalImport, 'innerText');

View File

@ -54,7 +54,7 @@ describe('Ticket Create packages path', () => {
it(`should confirm the first select is the expected one`, async() => { it(`should confirm the first select is the expected one`, async() => {
const result = await nightmare const result = await nightmare
.reloadSection('ticket.card.package') .reloadSection('ticket.card.package')
.waitForTextInInput(`${selectors.ticketPackages.firstPackageAutocomplete} input`, 'Container medical box 1m') .waitForTextInInput(selectors.ticketPackages.firstPackageAutocomplete, 'Container medical box 1m')
.waitToGetProperty(`${selectors.ticketPackages.firstPackageAutocomplete} input`, 'value'); .waitToGetProperty(`${selectors.ticketPackages.firstPackageAutocomplete} input`, 'value');
expect(result).toEqual('7 : Container medical box 1m'); expect(result).toEqual('7 : Container medical box 1m');

View File

@ -30,8 +30,8 @@ xdescribe('Claim detail', () => {
it('should edit de first item claimed quantity', async() => { it('should edit de first item claimed quantity', async() => {
const result = await nightmare const result = await nightmare
.clearInput(selectors.claimDetail.firstItemQuantityInput) .clearInput(selectors.claimDetail.firstItemQuantityInput) // selector deleted, find new upon fixes
.write(selectors.claimDetail.firstItemQuantityInput, 4) .write(selectors.claimDetail.firstItemQuantityInput, 4) // selector deleted, find new upon fixes
.write('body', '\u000d') // simulates enter .write('body', '\u000d') // simulates enter
.waitForLastSnackbar(); .waitForLastSnackbar();
@ -40,7 +40,7 @@ xdescribe('Claim detail', () => {
it('should confirm the first item quantity, and the claimed total were correctly edited', async() => { it('should confirm the first item quantity, and the claimed total were correctly edited', async() => {
const claimedQuantity = await nightmare const claimedQuantity = await nightmare
.waitToGetProperty(selectors.claimDetail.firstItemQuantityInput, 'value'); .waitToGetProperty(selectors.claimDetail.firstItemQuantityInput, 'value'); // selector deleted, find new upon fixes
const totalClaimed = await nightmare const totalClaimed = await nightmare
.waitToGetProperty(selectors.claimDetail.totalClaimed, 'innerText'); .waitToGetProperty(selectors.claimDetail.totalClaimed, 'innerText');