Skip to content

Commit

Permalink
Fixed report for random scenario when no error found; Updated isEleme…
Browse files Browse the repository at this point in the history
…ntVisible method to use puppeteer method to check element visibility
  • Loading branch information
Filipoliko committed Nov 16, 2018
1 parent 05bc9f1 commit 69807e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 95 deletions.
94 changes: 1 addition & 93 deletions src/actions/ActionsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,98 +39,6 @@ export default class ActionsHelper {
}

async isElementVisible(element) {
let executionContext = await element.executionContext();

return executionContext.evaluate(input => {
function isVisible(el, t, r, b, l, w, h) {
var p = el.parentNode,
VISIBLE_PADDING = 2;

if ( !_elementInDocument(el) ) {
return false;
}

//-- Return true for document node
if ( 9 === p.nodeType ) {
return true;
}

//-- Return false if our element is invisible
if (
'0' === _getStyle(el, 'opacity') ||
'none' === _getStyle(el, 'display') ||
'hidden' === _getStyle(el, 'visibility')
) {
return false;
}

if (
'undefined' === typeof(t) ||
'undefined' === typeof(r) ||
'undefined' === typeof(b) ||
'undefined' === typeof(l) ||
'undefined' === typeof(w) ||
'undefined' === typeof(h)
) {
t = el.offsetTop;
l = el.offsetLeft;
b = t + el.offsetHeight;
r = l + el.offsetWidth;
w = el.offsetWidth;
h = el.offsetHeight;
}
//-- If we have a parent, let's continue:
if ( p ) {
//-- Check if the parent can hide its children.
if ( ('hidden' === _getStyle(p, 'overflow') || 'scroll' === _getStyle(p, 'overflow')) ) {
//-- Only check if the offset is different for the parent
if (
//-- If the target element is to the right of the parent elm
l + VISIBLE_PADDING > p.offsetWidth + p.scrollLeft ||
//-- If the target element is to the left of the parent elm
l + w - VISIBLE_PADDING < p.scrollLeft ||
//-- If the target element is under the parent elm
t + VISIBLE_PADDING > p.offsetHeight + p.scrollTop ||
//-- If the target element is above the parent elm
t + h - VISIBLE_PADDING < p.scrollTop
) {
//-- Our target element is out of bounds:
return false;
}
}
//-- Add the offset parent's left/top coords to our element's offset:
if ( el.offsetParent === p ) {
l += p.offsetLeft;
t += p.offsetTop;
}
//-- Let's recursively check upwards:
return isVisible(p, t, r, b, l, w, h);
}
return true;
}

//-- Cross browser method to get style properties:
function _getStyle(el, property) {
if ( window.getComputedStyle ) {
return document.defaultView.getComputedStyle(el,null)[property];
}
if ( el.currentStyle ) {
return el.currentStyle[property];
}
}

function _elementInDocument(element) {
while (element = element.parentNode) {
if (element == document) {
return true;
}
}
return false;
}

let style = window.getComputedStyle(input, null);

return isVisible(input) && style.width > 0 && style.height > 0;
}, element);
return !!(await element.boundingBox());
}
}
8 changes: 6 additions & 2 deletions src/reporter/DefaultReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ export default class DefaultReporter extends EventEmitter {
* @param {Object} eventData
*/
_handleRandomScenarioEnd({ results }) {
console.log('Random scenario recieved following error.');
if (results.errors.length > 0) {
console.log('Random scenario recieved following error.');

results.errors.forEach(error => console.log(error));
results.errors.forEach(error => console.log(error));
} else {
console.log('Random scenario did not find any errors.');
}
}

/**
Expand Down

0 comments on commit 69807e1

Please sign in to comment.