UNPKG

testplane

Version:

Tests framework based on mocha and wdio

16 lines (15 loc) 14 kB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ "use strict";var lib=require("./lib.native.js");module.exports=function(e){return lib.queryAll(e)}; },{"./lib.native.js":3}],2:[function(require,module,exports){ (function (global){(function (){ "use strict";function prepareScreenshotUnsafe(e,t){var r=t.allowViewportOverflow,i=t.captureElementFromTop,o=t.disableAnimation,n=window;if(t.selectorToScroll&&!(n=document.querySelector(t.selectorToScroll)))return{error:"NOTFOUND",message:'Could not find element with css selector specified in "selectorToScroll" option: '+t.selectorToScroll,selector:t.selectorToScroll};var a,l=util.getMainDocumentElem(),c=l.clientWidth,s=l.clientHeight,u=l.scrollWidth,d=l.scrollHeight,f=new Rect({left:util.getScrollLeft(n),top:util.getScrollTop(n),width:c,height:s}),p=configurePixelRatio(t.usePixelRatio),m=[];if(e.forEach(function(e){Rect.isRect(e)?a=a?a.merge(new Rect(e)):new Rect(e):m.push(e)}),a=getCaptureRect(m,{initialRect:a,allowViewportOverflow:r,scrollElem:n,viewportWidth:c,documentHeight:d}),a.error)return a;if(i&&!f.rectInside(a))util.isSafariMobile()?scrollToCaptureAreaInSafari(f,a,n):n.scrollTo(a.left,a.top);else if(r&&f.rectIntersects(a))a.overflowsTopBound(f)&&a.recalculateHeight(f),a.overflowsLeftBound(f)&&a.recalculateWidth(f);else if(!i&&!r&&!f.rectIntersects(a))return{error:"OUTSIDE_OF_VIEWPORT",message:'Can not capture element, because it is outside of viewport. Try to set "captureElementFromTop=true" to scroll to it before capture or to set "allowViewportOverflow=true" to ignore viewport overflow error.'};return o&&disableFrameAnimationsUnsafe(),{captureArea:a.scale(p).serialize(),ignoreAreas:findIgnoreAreas(t.ignoreSelectors,{scrollElem:n,pixelRatio:p,viewportWidth:c,documentHeight:d}),viewport:new Rect({left:util.getScrollLeft(n),top:util.getScrollTop(n),width:c,height:s}).scale(p).serialize(),documentHeight:Math.ceil(d*p),documentWidth:Math.ceil(u*p),canHaveCaret:isEditable(document.activeElement),pixelRatio:p}}function disableFrameAnimationsUnsafe(){function e(e){var t=document.createElement("style");t.innerHTML=r+["{"," animation-delay: 0ms !important;"," animation-duration: 0ms !important;"," animation-timing-function: step-start !important;"," transition-timing-function: step-start !important;"," scroll-behavior: auto !important;"," transition: none !important;","}"].join("\n"),e.appendChild(t),i.push(t)}function t(){window.trustedTypes&&window.trustedTypes.createPolicy&&window.trustedTypes.createPolicy("default",{createHTML:function(e){return e}})}var r=["","::before","::after"].map(function(e){return"*:not(#testplane-q.testplane-w.testplane-e.testplane-r.testplane-t.testplane-y)"+e}).join(", "),i=[];util.forEachRoot(function(r){try{e(r)}catch(i){if(!(i&&i.message&&i.message.includes("This document requires 'TrustedHTML' assignment")))throw i;t(),e(r)}}),window.__cleanupAnimation=function(){for(var e=0;e<i.length;e++)i[e].parentNode.removeChild(i[e]);delete window.__cleanupAnimation}}function getCaptureRect(e,t){for(var r,i,o=t.initialRect,n=0;n<e.length;n++){if(!(r=lib.queryFirst(e[n])))return{error:"NOTFOUND",message:"Could not find element with css selector specified in setCaptureElements: "+e[n],selector:e[n]};i=getElementCaptureRect(r,t),i&&(o=o?o.merge(i):i)}return o?o.round():{error:"HIDDEN",message:"Area with css selector : "+e+" is hidden",selector:e}}function configurePixelRatio(e){return!1===e?1:window.devicePixelRatio?window.devicePixelRatio:window.screen.deviceXDPI/window.screen.logicalXDPI||1}function findIgnoreAreas(e,t){var r=[];return util.each(e,function(e){var i=queryIgnoreAreas(e);util.each(i,function(e){return addIgnoreArea.call(r,e,t)})}),r}function addIgnoreArea(e,t){var r=e&&getElementCaptureRect(e,t);if(r){var i=r.round().scale(t.pixelRatio).serialize();this.push(i)}}function isHidden(e,t){return"none"===e.display||"hidden"===e.visibility||e.opacity<1e-4||t.width<1e-4||t.height<1e-4}function getElementCaptureRect(e,t){var r=[":before",":after"],i=lib.getComputedStyle(e),o=rect.getAbsoluteClientRect(e,t);if(isHidden(i,o))return null;var n=getExtRect(i,o,t.allowViewportOverflow);return util.each(r,function(r){i=lib.getComputedStyle(e,r),n=n.merge(getExtRect(i,o,t.allowViewportOverflow))}),n}function getExtRect(e,t,r){var i=parseBoxShadow(e.boxShadow),o=parseInt(e.outlineWidth,10);return isNaN(o)&&(o=0),adjustRect(t,i,o,r)}function parseBoxShadow(e){e=e||"";var t,r=/[-+]?\d*\.?\d+px/g,i=e.split(","),o=[];return util.each(i,function(e){(t=e.match(r))&&o.push({offsetX:parseFloat(t[0]),offsetY:parseFloat(t[1])||0,blurRadius:parseFloat(t[2])||0,spreadRadius:parseFloat(t[3])||0,inset:-1!==e.indexOf("inset")})}),o}function adjustRect(e,t,r,i){var o=calculateShadowRect(e,t,i),n=calculateOutlineRect(e,r,i);return o.merge(n)}function calculateOutlineRect(e,t,r){var i=e.top-t,o=e.left-t;return new Rect({top:r?i:Math.max(0,i),left:r?o:Math.max(0,o),bottom:e.bottom+t,right:e.right+t})}function calculateShadowRect(e,t,r){var i=calculateShadowExtent(t),o=e.left+i.left,n=e.top+i.top;return new Rect({left:r?o:Math.max(0,o),top:r?n:Math.max(0,n),width:e.width-i.left+i.right,height:e.height-i.top+i.bottom})}function calculateShadowExtent(e){var t={top:0,left:0,right:0,bottom:0};return util.each(e,function(e){if(!e.inset){var r=e.spreadRadius+e.blurRadius;t.left=Math.min(e.offsetX-r,t.left),t.right=Math.max(e.offsetX+r,t.right),t.top=Math.min(e.offsetY-r,t.top),t.bottom=Math.max(e.offsetY+r,t.bottom)}}),t}function isEditable(e){return!!e&&(/^(input|textarea)$/i.test(e.tagName)||e.isContentEditable)}function scrollToCaptureAreaInSafari(e,t,r){var i=util.getMainDocumentElem(),o=Math.round(i.scrollHeight),n=Math.round(i.clientHeight),a=o-n;r.scrollTo(e.left,Math.min(t.top,a))}var util=require("./util"),rect=require("./rect"),lib=require("./lib.native.js"),queryIgnoreAreas=require("./ignore-areas"),Rect=rect.Rect;"undefined"==typeof window?global.__geminiCore=exports:window.__geminiCore=exports,exports.queryFirst=lib.queryFirst,exports.prepareScreenshot=function(e,t){t=t||{};try{return prepareScreenshotUnsafe(e,t)}catch(r){return{error:"JS",message:r.stack||r.message}}},exports.disableFrameAnimations=function(){try{return disableFrameAnimationsUnsafe()}catch(e){return{error:"JS",message:e.stack||e.message}}},exports.cleanupFrameAnimations=function(){window.__cleanupAnimation&&window.__cleanupAnimation()},exports.resetZoom=function(){var e=lib.queryFirst('meta[name="viewport"]');if(!e){e=document.createElement("meta"),e.name="viewport";var t=lib.queryFirst("head");t&&t.appendChild(e)}e.content="width=device-width,initial-scale=1.0,user-scalable=no"}; }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./ignore-areas":1,"./lib.native.js":3,"./rect":4,"./util":5}],3:[function(require,module,exports){ "use strict";var xpath=require("./xpath");exports.queryFirst=function(t){return xpath.isXpathSelector(t)?xpath.queryFirst(t):document.querySelector(t)},exports.queryAll=function(t){return xpath.isXpathSelector(t)?xpath.queryAll(t):document.querySelectorAll(t)},exports.getComputedStyle=function(t,e){return getComputedStyle(t,e)},exports.matchMedia=function(t){return matchMedia(t)},exports.trim=function(t){return t.trim()}; },{"./xpath":6}],4:[function(require,module,exports){ "use strict";function Rect(t){if(this.top=t.top,this.left=t.left,"width"in t&&"height"in t)this.width=t.width,this.height=t.height,this.bottom=t.bottom||this.top+this.height,this.right=t.right||this.left+this.width;else{if(!("bottom"in t&&"right"in t))throw new Error("Not enough data for the rect construction");this.bottom=t.bottom,this.right=t.right,this.width=t.right-Math.max(0,t.left),this.height=t.bottom-Math.max(0,t.top)}}function getNestedBoundingClientRect(t,e){var i=util.getOwnerIframe(t);if(null===i||util.getOwnerWindow(i)===e)return t.getBoundingClientRect();for(var o=[t.getBoundingClientRect()],r=i;r;){var h=getBoundingClientRectWithBorderOffset(r);if(o.push(h),(r=util.getOwnerIframe(r))&&util.getOwnerWindow(r)===e){h=getBoundingClientRectWithBorderOffset(r),o.push(h);break}}return mergeRectOffsets(o)}function getBoundingClientRectWithBorderOffset(t){var e=getElementDimensions(t);return mergeRectOffsets([t.getBoundingClientRect(),{top:e.borderTop,left:e.borderLeft,bottom:e.borderBottom,right:e.borderRight,x:e.borderLeft,y:e.borderTop}])}function getElementDimensions(t){var e=util.getOwnerWindow(t).getComputedStyle(t);return{borderLeft:parseFloat(e.borderLeftWidth),borderRight:parseFloat(e.borderRightWidth),borderTop:parseFloat(e.borderTopWidth),borderBottom:parseFloat(e.borderBottomWidth)}}function mergeRectOffsets(t){return t.reduce(function(t,e){if(null===t)return e;var i=t.top+e.top,o=t.left+e.left;return{top:i,left:o,width:t.width,height:t.height,bottom:i+t.height,right:o+t.width,x:o,y:i}})}var util=require("./util");Rect.isRect=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)&&("left"in t&&"top"in t&&("width"in t&&"height"in t||"right"in t&&"bottom"in t))},Rect.prototype={constructor:Rect,merge:function(t){return new Rect({left:Math.min(this.left,t.left),top:Math.min(this.top,t.top),bottom:Math.max(this.bottom,t.bottom),right:Math.max(this.right,t.right)})},translate:function(t,e){return new Rect({left:this.left+t,top:this.top+e,width:this.width,height:this.height})},pointInside:function(t,e){return t>=this.left&&t<=this.right&&e>=this.top&&e<=this.bottom},rectInside:function(t){return util.every(t._keyPoints(),function(t){return this.pointInside(t[0],t[1])},this)},rectIntersects:function(t){return!(t.right<=this.left||t.bottom<=this.top||t.left>=this.right||t.top>=this.bottom)},round:function(){return new Rect({top:Math.floor(this.top),left:Math.floor(this.left),right:Math.ceil(this.right),bottom:Math.ceil(this.bottom)})},scale:function(t){var e=new Rect({top:this.top*t,left:this.left*t,right:this.right*t,bottom:this.bottom*t});return util.isInteger(t)?e:e.round()},serialize:function(){return{left:this.left,top:this.top,width:this.width,height:this.height}},overflowsTopBound:function(t){return this._overflowsBound(t,"top")},overflowsLeftBound:function(t){return this._overflowsBound(t,"left")},recalculateHeight:function(t){this.height=this.height-(t.top-Math.max(0,this.top))},recalculateWidth:function(t){this.width=this.width-(t.left-Math.max(0,this.left))},_overflowsBound:function(t,e){return Math.max(0,this[e])<t[e]},_anyPointInside:function(t){return util.some(t,function(t){return this.pointInside(t[0],t[1])},this)},_keyPoints:function(){return[[this.left,this.top],[this.left,this.bottom],[this.right,this.top],[this.right,this.bottom]]}},exports.Rect=Rect,exports.getAbsoluteClientRect=function(t,e){var i=getNestedBoundingClientRect(t,window),o=i.width%e.viewportWidth,r=i.height%e.documentHeight;return new Rect({left:i.left,top:i.top,width:o>0&&o<1?e.viewportWidth:i.width,height:r>0&&r<1?e.documentHeight:i.height}).translate(util.getScrollLeft(e.scrollElem),util.getScrollTop(e.scrollElem))}; },{"./util":5}],5:[function(require,module,exports){ "use strict";function arrayUtil(e,t){return e?contextify(e):t}function contextify(e){return function(t){var r=Array.prototype.slice.call(arguments,1);return e.apply(t,r)}}function myForEach(e,t,r){for(var n=0;n<e.length;n++)t.call(r,e[n],n,e)}function mySome(e,t,r){for(var n=0;n<e.length;n++)if(t.call(r,e[n],n,e))return!0;return!1}function myEvery(e,t,r){for(var n=0;n<e.length;n++)if(!t.call(r,e[n],n,e))return!1;return!0}function getScroll(e,t,r){var n=SCROLL_DIR_NAME[t],o=PAGE_OFFSET_NAME[r];return e&&e!==window?e[n]:"undefined"!=typeof window[o]?window[o]:document.documentElement[n]}var SCROLL_DIR_NAME={top:"scrollTop",left:"scrollLeft"},PAGE_OFFSET_NAME={x:"pageXOffset",y:"pageYOffset"};exports.each=arrayUtil(Array.prototype.forEach,myForEach),exports.some=arrayUtil(Array.prototype.some,mySome),exports.every=arrayUtil(Array.prototype.every,myEvery),exports.getScrollTop=function(e){return getScroll(e,"top","y")},exports.getScrollLeft=function(e){return getScroll(e,"left","x")},exports.isSafariMobile=function(){return navigator&&"string"==typeof navigator.vendor&&navigator.vendor.match(/apple/i)&&/(iPhone|iPad).*AppleWebKit.*Safari/i.test(navigator.userAgent)},exports.isInteger=function(e){return e%1==0},exports.forEachRoot=function(e){function t(r){e(r);for(var n=document.createTreeWalker(r,NodeFilter.SHOW_ELEMENT,null,!1),o=n.currentNode;null!==o;o=n.nextNode())o instanceof Element&&o.shadowRoot&&t(o.shadowRoot)}t(document.documentElement)},exports.getOwnerWindow=function(e){return e.ownerDocument?e.ownerDocument.defaultView:null},exports.getOwnerIframe=function(e){var t=exports.getOwnerWindow(e);return t?t.frameElement:null},exports.getMainDocumentElem=function(e){e||(e=document.documentElement);var t=exports.getOwnerIframe(e);if(!t)return e;var r=exports.getOwnerWindow(t);return r?exports.getMainDocumentElem(r.document.documentElement):e}; },{}],6:[function(require,module,exports){ "use strict";function isXpathSelector(e){return XPATH_SELECTORS_START.some(function(t){return 0===e.indexOf(t)})}function queryFirst(e){return document.evaluate(e,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function queryAll(e){var t,u=document.evaluate(e,document,null,XPathResult.ANY_TYPE,null),r=[];for(t=u.iterateNext();t;)r.push(t),t=u.iterateNext();return r}var XPATH_SELECTORS_START=["/","(","../","./","*/"];module.exports={isXpathSelector:isXpathSelector,queryFirst:queryFirst,queryAll:queryAll}; },{}]},{},[2]);