E2E fixes
gitea/salix/pipeline/head This commit has test failures Details

This commit is contained in:
Juan Ferrer 2020-03-24 00:54:12 +01:00
parent 84bf240e71
commit c254604572
1 changed files with 55 additions and 54 deletions

View File

@ -1,4 +1,45 @@
function checkVisibility(selector) {
let selectorMatches = document.querySelectorAll(selector);
let element = selectorMatches[0];
if (selectorMatches.length > 1)
throw new Error(`Multiple matches of ${selector} found`);
let isVisible = false;
if (element) {
let eventHandler = event => {
event.preventDefault();
isVisible = true;
};
element.addEventListener('mouseover', eventHandler);
let rect = element.getBoundingClientRect();
let x = rect.left + rect.width / 2;
let y = rect.top + rect.height / 2;
let elementInCenter = document.elementFromPoint(x, y);
let elementInTopLeft = document.elementFromPoint(rect.left, rect.top);
let elementInBottomRight = document.elementFromPoint(rect.right, rect.bottom);
let e = new MouseEvent('mouseover', {
view: window,
bubbles: true,
cancelable: true,
});
if (elementInCenter)
elementInCenter.dispatchEvent(e);
if (elementInTopLeft)
elementInTopLeft.dispatchEvent(e);
if (elementInBottomRight)
elementInBottomRight.dispatchEvent(e);
element.removeEventListener('mouseover', eventHandler);
}
return isVisible;
}
let actions = {
clickIfExists: async function(selector) {
let exists;
@ -189,7 +230,7 @@ let actions = {
waitToClick: async function(selector) {
await this.waitForSelector(selector);
await this.checkVisibility(selector);
await this.waitForFunction(checkVisibility, {}, selector);
return await this.click(selector);
},
@ -209,52 +250,9 @@ let actions = {
}, selector);
},
checkVisibility: async function(selector) {
return await this.evaluate(function(selector) {
let selectorMatches = document.querySelectorAll(selector);
let element = selectorMatches[0];
if (selectorMatches.length > 1)
throw new Error(`Multiple matches of ${selector} found`);
let isVisible = false;
if (element) {
let eventHandler = event => {
event.preventDefault();
isVisible = true;
};
element.addEventListener('mouseover', eventHandler);
let rect = element.getBoundingClientRect();
let x = rect.left + rect.width / 2;
let y = rect.top + rect.height / 2;
let elementInCenter = document.elementFromPoint(x, y);
let elementInTopLeft = document.elementFromPoint(rect.left, rect.top);
let elementInBottomRight = document.elementFromPoint(rect.right, rect.bottom);
let e = new MouseEvent('mouseover', {
view: window,
bubbles: true,
cancelable: true,
});
if (elementInCenter)
elementInCenter.dispatchEvent(e);
if (elementInTopLeft)
elementInTopLeft.dispatchEvent(e);
if (elementInBottomRight)
elementInBottomRight.dispatchEvent(e);
element.removeEventListener('mouseover', eventHandler);
}
return isVisible;
}, selector);
},
isVisible: async function(selector) {
await this.waitForSelector(selector);
return await this.checkVisibility(selector);
return await this.evaluate(checkVisibility, selector);
},
waitImgLoad: async function(selector) {
@ -360,14 +358,17 @@ let actions = {
pickDate: async function(selector, date) {
date = date || new Date();
date = date.toISOString().substr(0, 10);
const tzoffset = date.getTimezoneOffset() * 60000;
const localIso = (new Date(date.getTime() - tzoffset))
.toISOString();
await this.wait(selector);
await this.evaluate((selector, date) => {
await this.evaluate((selector, localIso) => {
let input = document.querySelector(selector).$ctrl.input;
input.value = date;
input.value = localIso.substr(0, 10);
input.dispatchEvent(new Event('change'));
}, selector, date);
}, selector, localIso);
},
pickTime: async function(selector, time) {
@ -418,7 +419,7 @@ let actions = {
.querySelectorAll('li');
}, selector);
await this.write('.vn-drop-down.vn-popover.vn-popup.shown vn-textfield', searchValue);
await this.write('.vn-drop-down.shown vn-textfield', searchValue);
try {
await this.waitForFunction((selector, searchValue) => {
@ -430,7 +431,7 @@ let actions = {
}, {}, selector, searchValue);
} catch (error) {
let inputValue = await this.evaluate(() => {
return document.querySelector('.vn-drop-down.vn-popover.vn-popup.shown vn-textfield input').value;
return document.querySelector('.vn-drop-down.shown vn-textfield input').value;
});
throw new Error(`${builtSelector} value is ${inputValue}! ${error}`);
}
@ -532,9 +533,9 @@ let actions = {
},
respondToDialog: async function(response) {
await this.waitForSelector('.vn-dialog.vn-popup.shown');
await this.waitForSelector('.vn-dialog.shown');
const firstCount = await this.evaluate(text => {
const dialogs = document.querySelectorAll('.vn-dialog.vn-popup');
const dialogs = document.querySelectorAll('.vn-dialog');
const dialogOnTop = dialogs[dialogs.length - 1];
const button = dialogOnTop.querySelector(`div.buttons [response="${text}"]`);
button.click();
@ -542,7 +543,7 @@ let actions = {
}, response);
this.waitForFunction(firstCount => {
const dialogs = document.querySelectorAll('.vn-dialog.vn-popup');
const dialogs = document.querySelectorAll('.vn-dialog');
return dialogs.length < firstCount;
}, {}, firstCount);
},