w-puppeteer-uitest
Version:
A uitest package for web developer.
8 lines (7 loc) • 15 kB
JavaScript
/*!
* getB64 v1.0.41
* (c) 2018-2021 yuda-lyu(semisphere)
* Released under the MIT License.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("puppeteer")):"function"==typeof define&&define.amd?define(["puppeteer"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).getB64=e(t.puppeteer)}(this,(function(t){"use strict";var e=Array.isArray,r="object"==typeof global&&global&&global.Object===Object&&global,n="object"==typeof self&&self&&self.Object===Object&&self,o=r||n||Function("return this")(),i=o.Symbol,a=Object.prototype,u=a.hasOwnProperty,c=a.toString,l=i?i.toStringTag:void 0;var f=Object.prototype.toString;var s="[object Null]",p="[object Undefined]",y=i?i.toStringTag:void 0;function h(t){return null==t?void 0===t?p:s:y&&y in Object(t)?function(t){var e=u.call(t,l),r=t[l];try{t[l]=void 0;var n=!0}catch(t){}var o=c.call(t);return n&&(e?t[l]=r:delete t[l]),o}(t):function(t){return f.call(t)}(t)}function w(t){return null!=t&&"object"==typeof t}var v="[object Symbol]";function d(t){return"symbol"==typeof t||w(t)&&h(t)==v}var b=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,g=/^\w*$/;function j(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var m="[object AsyncFunction]",_="[object Function]",F="[object GeneratorFunction]",O="[object Proxy]";function x(t){if(!j(t))return!1;var e=h(t);return e==_||e==F||e==m||e==O}var A,k=o["__core-js_shared__"],S=(A=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||""))?"Symbol(src)_1."+A:"";var $=Function.prototype.toString;var z=/^\[object .+?Constructor\]$/,P=Function.prototype,C=Object.prototype,T=P.toString,B=C.hasOwnProperty,E=RegExp("^"+T.call(B).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function N(t){return!(!j(t)||(e=t,S&&S in e))&&(x(t)?E:z).test(function(t){if(null!=t){try{return $.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t));var e}function I(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return N(r)?r:void 0}var M=I(Object,"create");var U=Object.prototype.hasOwnProperty;var q=Object.prototype.hasOwnProperty;function R(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function V(t,e){for(var r,n,o=t.length;o--;)if((r=t[o][0])===(n=e)||r!=r&&n!=n)return o;return-1}R.prototype.clear=function(){this.__data__=M?M(null):{},this.size=0},R.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},R.prototype.get=function(t){var e=this.__data__;if(M){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return U.call(e,t)?e[t]:void 0},R.prototype.has=function(t){var e=this.__data__;return M?void 0!==e[t]:q.call(e,t)},R.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=M&&void 0===e?"__lodash_hash_undefined__":e,this};var D=Array.prototype.splice;function G(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}G.prototype.clear=function(){this.__data__=[],this.size=0},G.prototype.delete=function(t){var e=this.__data__,r=V(e,t);return!(r<0)&&(r==e.length-1?e.pop():D.call(e,r,1),--this.size,!0)},G.prototype.get=function(t){var e=this.__data__,r=V(e,t);return r<0?void 0:e[r][1]},G.prototype.has=function(t){return V(this.__data__,t)>-1},G.prototype.set=function(t,e){var r=this.__data__,n=V(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var L=I(o,"Map");function W(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function H(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}H.prototype.clear=function(){this.size=0,this.__data__={hash:new R,map:new(L||G),string:new R}},H.prototype.delete=function(t){var e=W(this,t).delete(t);return this.size-=e?1:0,e},H.prototype.get=function(t){return W(this,t).get(t)},H.prototype.has=function(t){return W(this,t).has(t)},H.prototype.set=function(t,e){var r=W(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};var J="Expected a function";function K(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(J);var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(K.Cache||H),r}K.Cache=H;var Q,X,Y,Z=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,tt=/\\(\\)?/g,et=(Q=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Z,(function(t,r,n,o){e.push(n?o.replace(tt,"$1"):r||t)})),e},X=K(Q,(function(t){return 500===Y.size&&Y.clear(),t})),Y=X.cache,X),rt=et;var nt=1/0,ot=i?i.prototype:void 0,it=ot?ot.toString:void 0;function at(t){if("string"==typeof t)return t;if(e(t))return function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}(t,at)+"";if(d(t))return it?it.call(t):"";var r=t+"";return"0"==r&&1/t==-nt?"-0":r}function ut(t){return null==t?"":at(t)}function ct(t,r){return e(t)?t:function(t,r){if(e(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!d(t))||g.test(t)||!b.test(t)||null!=r&&t in Object(r)}(t,r)?[t]:rt(ut(t))}var lt=1/0;function ft(t){if("string"==typeof t||d(t))return t;var e=t+"";return"0"==e&&1/t==-lt?"-0":e}function st(t,e,r){var n=null==t?void 0:function(t,e){for(var r=0,n=(e=ct(e,t)).length;null!=t&&r<n;)t=t[ft(e[r++])];return r&&r==n?t:void 0}(t,e);return void 0===n?r:n}var pt=/\s/;var yt=/^\s+/;function ht(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&pt.test(t.charAt(e)););return e}(t)+1).replace(yt,""):t}var wt=NaN,vt=/^[-+]0x[0-9a-f]+$/i,dt=/^0b[01]+$/i,bt=/^0o[0-7]+$/i,gt=parseInt;function jt(t){if("number"==typeof t)return t;if(d(t))return wt;if(j(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=j(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=ht(t);var r=dt.test(t);return r||bt.test(t)?gt(t.slice(2),r?2:8):vt.test(t)?wt:+t}var mt=1/0,_t=17976931348623157e292;function Ft(t){return t?(t=jt(t))===mt||t===-mt?(t<0?-1:1)*_t:t==t?t:0:0===t?t:0}function Ot(t){var e=Ft(t),r=e%1;return e==e?r?e-r:e:0}function xt(t){return"[object String]"===Object.prototype.toString.call(t)}function At(t){return t!=t}function kt(t){let e=!1;if(function(t){return!(!xt(t)||""===t)}(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(At(t))return!1;e=!0}return e}function St(t){if(!kt(t))return 0;return Ft(t)}function $t(t){return!!kt(t)&&(t=St(t),"number"==typeof(e=t)&&e==Ot(e));var e}function zt(t){return"[object Object]"===Object.prototype.toString.call(t)}function Pt(t){return"[object Array]"===Object.prototype.toString.call(t)}var Ct="[object Boolean]";function Tt(t){return!0===(e=t)||!1===e||w(e)&&h(e)==Ct;var e}function Bt(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(zt(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!xt(t)||""!==t)}(t)||(!!function(t){return!!Pt(t)&&0===t.length}(t)||!!At(t)))))}var Et=o.isFinite,Nt=Math.min;var It=function(t){var e=Math[t];return function(t,r){if(t=jt(t),(r=null==r?0:Nt(Ot(r),292))&&Et(t)){var n=(ut(t)+"e").split("e");return+((n=(ut(e(n[0]+"e"+(+n[1]+r)))+"e").split("e"))[0]+"e"+(+n[1]-r))}return e(t)}}("round"),Mt=It;function Ut(t){if(!kt(t))return 0;t=St(t);let e=Mt(t);return"0"===String(e)?0:e}function qt(t,e,r){var n=null==t?0:t.length;return n?function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i}(t,(e=r||void 0===e?1:Ot(e))<0?0:e,n):[]}function Rt(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}var Vt,Dt=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[Vt?a:++n];if(!1===e(o[u],u,o))break}return t};function Gt(t){return w(t)&&"[object Arguments]"==h(t)}var Lt=Object.prototype,Wt=Lt.hasOwnProperty,Ht=Lt.propertyIsEnumerable,Jt=Gt(function(){return arguments}())?Gt:function(t){return w(t)&&Wt.call(t,"callee")&&!Ht.call(t,"callee")},Kt=Jt;var Qt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Xt=Qt&&"object"==typeof module&&module&&!module.nodeType&&module,Yt=Xt&&Xt.exports===Qt?o.Buffer:void 0,Zt=(Yt?Yt.isBuffer:void 0)||function(){return!1},te=9007199254740991,ee=/^(?:0|[1-9]\d*)$/;function re(t,e){var r=typeof t;return!!(e=null==e?te:e)&&("number"==r||"symbol"!=r&&ee.test(t))&&t>-1&&t%1==0&&t<e}var ne=9007199254740991;function oe(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=ne}var ie={};ie["[object Float32Array]"]=ie["[object Float64Array]"]=ie["[object Int8Array]"]=ie["[object Int16Array]"]=ie["[object Int32Array]"]=ie["[object Uint8Array]"]=ie["[object Uint8ClampedArray]"]=ie["[object Uint16Array]"]=ie["[object Uint32Array]"]=!0,ie["[object Arguments]"]=ie["[object Array]"]=ie["[object ArrayBuffer]"]=ie["[object Boolean]"]=ie["[object DataView]"]=ie["[object Date]"]=ie["[object Error]"]=ie["[object Function]"]=ie["[object Map]"]=ie["[object Number]"]=ie["[object Object]"]=ie["[object RegExp]"]=ie["[object Set]"]=ie["[object String]"]=ie["[object WeakMap]"]=!1;var ae="object"==typeof exports&&exports&&!exports.nodeType&&exports,ue=ae&&"object"==typeof module&&module&&!module.nodeType&&module,ce=ue&&ue.exports===ae&&r.process,le=function(){try{var t=ue&&ue.require&&ue.require("util").types;return t||ce&&ce.binding&&ce.binding("util")}catch(t){}}(),fe=le&&le.isTypedArray,se=fe?function(t){return function(e){return t(e)}}(fe):function(t){return w(t)&&oe(t.length)&&!!ie[h(t)]},pe=se,ye=Object.prototype.hasOwnProperty;function he(t,r){var n=e(t),o=!n&&Kt(t),i=!n&&!o&&Zt(t),a=!n&&!o&&!i&&pe(t),u=n||o||i||a,c=u?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],l=c.length;for(var f in t)!r&&!ye.call(t,f)||u&&("length"==f||i&&("offset"==f||"parent"==f)||a&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||re(f,l))||c.push(f);return c}var we=Object.prototype;var ve=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),de=ve,be=Object.prototype.hasOwnProperty;function ge(t){if(r=(e=t)&&e.constructor,e!==("function"==typeof r&&r.prototype||we))return de(t);var e,r,n=[];for(var o in Object(t))be.call(t,o)&&"constructor"!=o&&n.push(o);return n}function je(t){return null!=t&&oe(t.length)&&!x(t)}function me(t){return je(t)?he(t):ge(t)}var _e=function(t,e){return function(r,n){if(null==r)return r;if(!je(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););return r}}((function(t,e){return t&&Dt(t,e,me)})),Fe=_e;function Oe(t){return t}function xe(t,r){var n;return(e(t)?Rt:Fe)(t,"function"==typeof(n=r)?n:Oe)}function Ae(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function ke(t,e){let r=function(){let t,e,r=new Promise((function(){t=arguments[0],e=arguments[1]}));return r.resolve=t,r.reject=e,r}();if(!Pt(t)&&!zt(t))return r.reject("rs is not an array or object"),r;let n=!1;if(zt(t)){n=!0;let e=[];xe(t,((t,r)=>{e.push({k:r,v:t})})),t=e}Ae(e)||(e=function(t){return t});let o=-1,i=[];return t.reduce((function(t,r){return t.then((function(t){i.push(t),o+=1;let a=o,u=r;return n&&(a=r.k,u=r.v),Ae(e)?e(u,a):u}))}),Promise.resolve()).then((function(t){i.push(t),i=qt(i),r.resolve(i)})).catch((function(t){r.reject(t)})),r}return async function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=st(r,"headless");Tt(n)||(n=!0);let o=st(r,"viewport");zt(o)||(o={x:0,y:0,width:800,height:600});let i=st(r,"actions");Pt(i)||(i=[]);let a=st(r,"waitsec");$t(a)||(a=5);let u={headless:n,slowMo:20},c=await t.launch(u),l=await c.newPage();async function f(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(r=Ut(r),0===r){if(e=await l.$(t),Bt(e))return console.log("page.$ get no result: "+t),null}else{let n=await l.$$(t);if(0===n.length)return console.log("page.$$ get no result: "+t),null;e=r<0?n[n.length+r]:n[r]}if(Bt(e))return console.log("invalid ele: "+t),null;if(Bt(e.boundingBox))return console.log("invalid ele.boundingBox: "+t),null;let n=await e.boundingBox();return n.cx=n.x+n.width/2,n.cy=n.y+n.height/2,n.ele=e,n}await l.goto(e),await l.setViewport(o),await l.waitFor(1e3*a),await ke(i,(async function(t){if("wait"===t.mode)await l.waitFor(t.time);else if("resize"===t.mode)await l.waitFor(300),await l.setViewport({x:0,y:0,width:t.width,height:t.height}),await l.waitFor(300);else if("move"===t.mode)await l.waitFor(300),await l.mouse.move(t.x1,t.y1),await l.waitFor(300);else if("elemove"===t.mode){await l.waitFor(300);let e=await f(t.selector,t.nth);e&&(await l.mouse.move(e.cx,e.cy),await l.waitFor(300))}else if("elehover"===t.mode)await l.waitFor(300),await l.hover(t.selector),await l.waitFor(300);else if("drag"===t.mode)await l.waitFor(300),await l.mouse.move(t.x1,t.y1),await l.mouse.down(),await l.waitFor(300),await l.mouse.move(t.x2,t.y2,{steps:50}),await l.waitFor(300),await l.mouse.up(),await l.waitFor(300);else if("eledrag"===t.mode){await l.waitFor(300);let e=await f(t.selector,t.nth);e&&(await l.mouse.move(e.cx,e.cy),await l.mouse.down(),await l.waitFor(300),await l.mouse.move(e.cx+t.shiftx,e.cy+t.shifty,{steps:50}),await l.waitFor(300),await l.mouse.up(),await l.waitFor(300))}else if("click"===t.mode)await l.waitFor(300),await l.mouse.move(t.x1,t.y1),await l.mouse.down(),await l.mouse.up(),await l.waitFor(300);else if("eleclick"===t.mode){await l.waitFor(300);let e=await f(t.selector,t.nth);e&&(await e.ele.click(),await l.waitFor(300))}else if("dbclick"===t.mode)await l.waitFor(300),await l.mouse.click(t.x1,t.y1,{clickCount:2}),await l.waitFor(300);else if("eledbclick"===t.mode){await l.waitFor(300);let e=await f(t.selector,t.nth);e&&(await e.ele.click({clickCount:2}),await l.waitFor(300))}else if("type"===t.mode)await l.waitFor(300),await l.keyboard.type(t.str,{delay:50}),t.noEnter||await l.keyboard.type(String.fromCharCode(13)),await l.waitFor(300);else if("eletype"===t.mode){await l.waitFor(300);let e=await f(t.selector,t.nth);e&&(await e.ele.click(),await l.waitFor(50),await l.keyboard.type(t.str,{delay:50}),t.noEnter||await l.keyboard.type(String.fromCharCode(13)),await l.waitFor(300))}else if("keypress"===t.mode){await l.waitFor(300);let e=Ut(t.count);e<=0&&(e=1);for(let r=0;r<e;r++)await l.keyboard.press(t.key);await l.waitFor(300)}else if("elefocus"===t.mode){await l.waitFor(300);let e=await f(t.selector,t.nth);e&&(await e.ele.focus(),await l.waitFor(300))}else console.log("mode is unrecognized: "+t.mode)})),await l.waitFor(2e3);let s=await l.screenshot({encoding:"base64"});return await l.close(),await c.close(),s}}));
//# sourceMappingURL=getB64.umd.js.map