From 17e9d83d70d83f0228428e121a1a14721bea3c84 Mon Sep 17 00:00:00 2001 From: wangjinxin613 <1749574663@qq.com> Date: Fri, 29 Mar 2024 16:58:54 +0800 Subject: [PATCH] =?UTF-8?q?chore(automator):=20=E4=BF=AE=E5=A4=8D=20ios=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B5=8B=E8=AF=95=20app-webview=20?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=8D=A1=E4=BD=8F=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-app-plus/lib/automator.js | 2 +- packages/uni-app-uts/lib/automator/ios/automator.js | 2 +- .../lib/app-webview/project/pages/index/index.uvue | 12 +++++++++++- packages/uni-h5/lib/automator.js | 2 +- packages/uni-mp-baidu/lib/automator.js | 2 +- packages/uni-mp-weixin/lib/automator.js | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/uni-app-plus/lib/automator.js b/packages/uni-app-plus/lib/automator.js index 5fb157df16..06e92387f2 100644 --- a/packages/uni-app-plus/lib/automator.js +++ b/packages/uni-app-plus/lib/automator.js @@ -12,4 +12,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i0)return firstSocketTaskEmitter(__assign({method:method.replace("Socket","")},args[0])).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}));if(!uni[method])return reject(Error("uni."+method+" not exists"));if(isSyncApi(method))return resolve({result:uni[method].apply(uni,args)});var params=[Object.assign({},args[0]||{},{success:function(result){setTimeout((function(){resolve({result:result})}),"pageScrollTo"===method?350:0)},fail:function(res){reject(Error(res.errMsg.replace(method+":fail ","")))}})];uni[method].apply(uni,params)}else(id=args[0].id,url=args[0].url,new Promise((function(resolve,reject){var socketTask=uni.connectSocket({url:url,success:function(){resolve({result:{errMsg:"connectSocket:ok"}})},fail:function(){reject({result:{errMsg:"connectSocket:fail"}})}});socketInstanceMap.set(id,{instance:socketTask,isOpend:!1}),socketTask.onOpen((function(data){socketInstanceMap.get(id).isOpend=!0,socketInstanceMap.get(id).openData=data}))}))).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}))}))},mockUniMethod:function(params){var method=params.method;if(!uni[method])throw Error("uni."+method+" not exists");if(!function(method){return!MOCK_API_BLACKLIST_RE.test(method)}(method))throw Error("You can't mock uni."+method);var mockFn,result=params.result,functionDeclaration=params.functionDeclaration;return isUndef(result)&&isUndef(functionDeclaration)?(originUni[method]&&(uni[method]=originUni[method],delete originUni[method]),Promise.resolve()):(mockFn=isUndef(functionDeclaration)?isSyncApi(method)?function(){return result}:function(params){setTimeout((function(){result.errMsg&&-1!==result.errMsg.indexOf(":fail")?params.fail&¶ms.fail(result):params.success&¶ms.success(result),params.complete&¶ms.complete(result)}),4)}:function(){for(var args=[],_i=0;_i"+formatHTML(toHTML(node,"inner"))+"":formatHTML(node.toString()):formatHTML(node.pureChildren.map((function(child){return child.toString()})).join(""))}var FUNCTIONS={input:{input:function(el,value){el.setValue(value)}},textarea:{input:function(el,value){el.setValue(value)}},"scroll-view":{scrollTo:function(el,x,y){el.scrollTo(y)},scrollTop:function(el){return 0},scrollLeft:function(el){return 0},scrollWidth:function(el){return 0},scrollHeight:function(el){return 0}},swiper:{swipeTo:function(el,index){el.__vue__.current=index}},"movable-view":{moveTo:function(el,x,y){var vm=el.__vue__;vm.x=x,vm.y=y}},switch:{tap:function(el){var vm=el.__vue__;vm.checked=!vm.checked}},slider:{slideTo:function(el,value){el.__vue__.value=value}}};function getRoot(pageId){return getDocument(pageId).body}var NativeAdapter={getWindow:function(pageId){return getRoot(pageId)},getDocument:function(pageId){return getRoot(pageId)},getEl:function(elementId,pageId){var element=getDocument(pageId).getRef(elementId);if(!element)throw Error("element destroyed");return element},getOffset:function(node){var weex=node.__$weex__||node.ownerDocument.__$weex__;return new Promise((function(resolve){weex.requireModule("dom").getComponentRect(node.ref,(function(res){res.result?resolve({left:res.size.left,top:res.size.top}):resolve({left:0,top:0})}))}))},querySelector:function(context,selector){return Promise.resolve(transEl(querySelector(context,selector)))},querySelectorAll:function(context,selector){return Promise.resolve({elements:querySelector(context,selector,[]).map((function(el){return transEl(el)}))})},queryProperties:function(context,names){var options=DOM_PROPERTIES.find((function(options){return options.test(names,context)}));return options?options.call(context).then((function(properties){return{properties:properties}})):Promise.resolve({properties:names.map((function(name){return getDataByPath(context,name)}))})},queryAttributes:function(context,names){var attr=context.attr;return Promise.resolve({attributes:names.map((function(name){return"class"===name?(context.classList||[]).join(" "):String(attr[name]||attr[camelize(name)]||"")}))})},queryStyles:function(context,names){var style=context.style;return Promise.resolve({styles:names.map((function(name){return style[name]}))})},queryHTML:function(context,type){return Promise.resolve({html:toHTML(context,type)})},dispatchTapEvent:function(el){return el.fireEvent("click",{timeStamp:Date.now(),target:el,currentTarget:el},!0),Promise.resolve()},dispatchLongpressEvent:function(el){return el.fireEvent("longpress",{timeStamp:Date.now(),target:el,currentTarget:el},!0),Promise.resolve()},dispatchTouchEvent:function(el,type,eventInitDict){return eventInitDict||(eventInitDict={}),eventInitDict.touches||(eventInitDict.touches=[]),eventInitDict.changedTouches||(eventInitDict.changedTouches=[]),eventInitDict.touches.length||eventInitDict.touches.push({identifier:Date.now(),target:el}),el.fireEvent(type,Object.assign({timeStamp:Date.now(),target:el,currentTarget:el},eventInitDict),!0),Promise.resolve()},callFunction:function(el,functionName,args){var fn=getDataByPath(FUNCTIONS,functionName);return fn?Promise.resolve({result:fn.apply(null,__spreadArrays([el],args))}):Promise.reject(Error(functionName+" not exists"))},triggerEvent:function(el,type,detail){var vm=el.__vue__;return vm?vm.$trigger&&vm.$trigger(type,{},detail):el.fireEvent(type,{timeStamp:Date.now(),target:el,currentTarget:el},!1,{params:[{detail:detail}]}),Promise.resolve()}};function initNativeApi(){return Object.assign({},function(adapter){return{"Page.getElement":function(params){return adapter.querySelector(adapter.getDocument(params.pageId),params.selector)},"Page.getElements":function(params){return adapter.querySelectorAll(adapter.getDocument(params.pageId),params.selector)},"Page.getWindowProperties":function(params){return adapter.queryProperties(adapter.getWindow(params.pageId),params.names)}}}(NativeAdapter),function(adapter){var getEl=function(params){return adapter.getEl(params.elementId,params.pageId)};return{"Element.getElement":function(params){return adapter.querySelector(getEl(params),params.selector)},"Element.getElements":function(params){return adapter.querySelectorAll(getEl(params),params.selector)},"Element.getDOMProperties":function(params){return adapter.queryProperties(getEl(params),params.names)},"Element.getProperties":function(params){var el=getEl(params),ctx=el.__vue__||el.attr||{};return el.__vueParentComponent&&(ctx=Object.assign({},ctx,el.__vueParentComponent.attrs,el.__vueParentComponent.props)),adapter.queryProperties(ctx,params.names)},"Element.getOffset":function(params){return adapter.getOffset(getEl(params))},"Element.getAttributes":function(params){return adapter.queryAttributes(getEl(params),params.names)},"Element.getStyles":function(params){return adapter.queryStyles(getEl(params),params.names)},"Element.getHTML":function(params){return adapter.queryHTML(getEl(params),params.type)},"Element.tap":function(params){return adapter.dispatchTapEvent(getEl(params))},"Element.longpress":function(params){return adapter.dispatchLongpressEvent(getEl(params))},"Element.touchstart":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchstart",params)},"Element.touchmove":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchmove",params)},"Element.touchend":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchend",params)},"Element.callFunction":function(params){return adapter.callFunction(getEl(params),params.functionName,params.args)},"Element.triggerEvent":function(params){return adapter.triggerEvent(getEl(params),params.type,params.detail)}}}(NativeAdapter))}var E=function(){};E.prototype={on:function(name,callback,ctx){var e=this.e||(this.e={});return(e[name]||(e[name]=[])).push({fn:callback,ctx:ctx}),this},once:function(name,callback,ctx){var self=this;function listener(){self.off(name,listener),callback.apply(ctx,arguments)}return listener._=callback,this.on(name,listener,ctx)},emit:function(name){for(var data=[].slice.call(arguments,1),evtArr=((this.e||(this.e={}))[name]||[]).slice(),i=0,len=evtArr.length;i=0;i--)if(evts[i].fn===callback||evts[i].fn._===callback){evts.splice(i,1);break}liveEvents=evts}return liveEvents.length?e[name]=liveEvents:delete e[name],this}};var Emitter=E;function initBridge(subscribeNamespace){var emitter=new Emitter;return{subscribe:function(event,callback,once){void 0===once&&(once=!1),emitter[once?"once":"on"](subscribeNamespace+"."+event,callback)},subscribeHandler:function(event,args,pageId){emitter.emit(subscribeNamespace+"."+event,args,pageId)}}}var extend=Object.assign,UniXServiceJSBridge=extend(initBridge("service"),{publishHandler:function(event,args,pageId){UniViewJSBridge.subscribeHandler(event,args,pageId)}}),UniXViewJSBridge=extend(initBridge("view"),{publishHandler:function(event,args,pageId){UniServiceJSBridge.subscribeHandler(event,args,pageId)}});if("undefined"==typeof UniServiceJSBridge&&"undefined"==typeof UniViewJSBridge){var __global__="undefined"==typeof globalThis?Function("return this")():globalThis;__global__.UniServiceJSBridge=UniXServiceJSBridge,__global__.UniViewJSBridge=UniXViewJSBridge}var Api={};Object.keys(App$1).forEach((function(method){Api["App."+method]=App$1[method]})),Object.keys(Page$1).forEach((function(method){Api["Page."+method]=Page$1[method]})),Object.keys(Element$1).forEach((function(method){Api["Element."+method]=Element$1[method]}));var NVueApi,fallback,socketTask,wsEndpoint=process.env.UNI_AUTOMATOR_WS_ENDPOINT;function send(data){socketTask.send({data:JSON.stringify(data)})}function onMessage(res){var _a=JSON.parse(res.data),id=_a.id,method=_a.method,params=_a.params,data={id:id},fn=Api[method];if(!fn){if(fallback){var result=fallback(id,method,params,data);if(!0===result)return;fn=result}if(!fn)return data.error={message:method+" unimplemented"},send(data)}try{fn(params,send).then((function(res){res&&(data.result=res)})).catch((function(err){data.error={message:err.message}})).finally((function(){send(data)}))}catch(err){data.error={message:err.message},send(data)}}fallback=function(id,method,params,data){var pageId=params.pageId,page=function(pageId){var pages=getCurrentPages();if(!pageId)return pages[pages.length-1];return pages.find((function(page){return page.$page.id===pageId}))}(pageId);return page?!page.$page.meta.isNVue?(UniServiceJSBridge.publishHandler("sendAutoMessage",{id:id,method:method,params:params},pageId),!0):(NVueApi||(NVueApi=initNativeApi()),NVueApi[method]):(data.error={message:"page["+pageId+"] not exists"},send(data),!0)},UniServiceJSBridge.subscribe("onAutoMessageReceive",(function(res){send(res)})),setTimeout((function(){if("undefined"!=typeof window&&window.__uniapp_x_)!function(data,callback){var id=0;callback&&(id=postMessageId++,postMessageCallbacks[id]=callback);var message={data:{id:id,type:"automator",data:data}};console.log("postMessageToUniXWebView",message),"undefined"!=typeof window&&window.__uniapp_x_.postMessage(JSON.stringify(message))}({action:"ready"});else{if(wsEndpoint&&wsEndpoint.endsWith(":0000"))return;void 0===options&&(options={}),(socketTask=uni.connectSocket({url:options.wsEndpoint||wsEndpoint,complete:function(){}})).onMessage(onMessage),socketTask.onOpen((function(res){options.success&&options.success(),console.log("已开启自动化测试...")})),socketTask.onError((function(res){console.log("automator.onError",res)})),socketTask.onClose((function(){options.fail&&options.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))}var options}),500);export{send}; +var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i0)return firstSocketTaskEmitter(__assign({method:method.replace("Socket","")},args[0])).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}));if(!uni[method])return reject(Error("uni."+method+" not exists"));if(isSyncApi(method))return resolve({result:uni[method].apply(uni,args)});var params=[Object.assign({},args[0]||{},{success:function(result){setTimeout((function(){resolve({result:result})}),"pageScrollTo"===method?350:0)},fail:function(res){reject(Error(res.errMsg.replace(method+":fail ","")))}})];uni[method].apply(uni,params)}else(id=args[0].id,url=args[0].url,new Promise((function(resolve,reject){var socketTask=uni.connectSocket({url:url,success:function(){resolve({result:{errMsg:"connectSocket:ok"}})},fail:function(){reject({result:{errMsg:"connectSocket:fail"}})}});socketInstanceMap.set(id,{instance:socketTask,isOpend:!1}),socketTask.onOpen((function(data){socketInstanceMap.get(id).isOpend=!0,socketInstanceMap.get(id).openData=data}))}))).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}))}))},mockUniMethod:function(params){var method=params.method;if(!uni[method])throw Error("uni."+method+" not exists");if(!function(method){return!MOCK_API_BLACKLIST_RE.test(method)}(method))throw Error("You can't mock uni."+method);var mockFn,result=params.result,functionDeclaration=params.functionDeclaration;return isUndef(result)&&isUndef(functionDeclaration)?(originUni[method]&&(uni[method]=originUni[method],delete originUni[method]),Promise.resolve()):(mockFn=isUndef(functionDeclaration)?isSyncApi(method)?function(){return result}:function(params){setTimeout((function(){result.errMsg&&-1!==result.errMsg.indexOf(":fail")?params.fail&¶ms.fail(result):params.success&¶ms.success(result),params.complete&¶ms.complete(result)}),4)}:function(){for(var args=[],_i=0;_i"+formatHTML(toHTML(node,"inner"))+"":formatHTML(node.toString()):formatHTML(node.pureChildren.map((function(child){return child.toString()})).join(""))}var FUNCTIONS={input:{input:function(el,value){el.setValue(value)}},textarea:{input:function(el,value){el.setValue(value)}},"scroll-view":{scrollTo:function(el,x,y){el.scrollTo(y)},scrollTop:function(el){return 0},scrollLeft:function(el){return 0},scrollWidth:function(el){return 0},scrollHeight:function(el){return 0}},swiper:{swipeTo:function(el,index){el.__vue__.current=index}},"movable-view":{moveTo:function(el,x,y){var vm=el.__vue__;vm.x=x,vm.y=y}},switch:{tap:function(el){var vm=el.__vue__;vm.checked=!vm.checked}},slider:{slideTo:function(el,value){el.__vue__.value=value}}};function getRoot(pageId){return getDocument(pageId).body}var NativeAdapter={getWindow:function(pageId){return getRoot(pageId)},getDocument:function(pageId){return getRoot(pageId)},getEl:function(elementId,pageId){var element=getDocument(pageId).getRef(elementId);if(!element)throw Error("element destroyed");return element},getOffset:function(node){var weex=node.__$weex__||node.ownerDocument.__$weex__;return new Promise((function(resolve){weex.requireModule("dom").getComponentRect(node.ref,(function(res){res.result?resolve({left:res.size.left,top:res.size.top}):resolve({left:0,top:0})}))}))},querySelector:function(context,selector){return Promise.resolve(transEl(querySelector(context,selector)))},querySelectorAll:function(context,selector){return Promise.resolve({elements:querySelector(context,selector,[]).map((function(el){return transEl(el)}))})},queryProperties:function(context,names){var options=DOM_PROPERTIES.find((function(options){return options.test(names,context)}));return options?options.call(context).then((function(properties){return{properties:properties}})):Promise.resolve({properties:names.map((function(name){return getDataByPath(context,name)}))})},queryAttributes:function(context,names){var attr=context.attr;return Promise.resolve({attributes:names.map((function(name){return"class"===name?(context.classList||[]).join(" "):String(attr[name]||attr[camelize(name)]||"")}))})},queryStyles:function(context,names){var style=context.style;return Promise.resolve({styles:names.map((function(name){return style[name]}))})},queryHTML:function(context,type){return Promise.resolve({html:toHTML(context,type)})},dispatchTapEvent:function(el){return el.fireEvent("click",{timeStamp:Date.now(),target:el,currentTarget:el},!0),Promise.resolve()},dispatchLongpressEvent:function(el){return el.fireEvent("longpress",{timeStamp:Date.now(),target:el,currentTarget:el},!0),Promise.resolve()},dispatchTouchEvent:function(el,type,eventInitDict){return eventInitDict||(eventInitDict={}),eventInitDict.touches||(eventInitDict.touches=[]),eventInitDict.changedTouches||(eventInitDict.changedTouches=[]),eventInitDict.touches.length||eventInitDict.touches.push({identifier:Date.now(),target:el}),el.fireEvent(type,Object.assign({timeStamp:Date.now(),target:el,currentTarget:el},eventInitDict),!0),Promise.resolve()},callFunction:function(el,functionName,args){var fn=getDataByPath(FUNCTIONS,functionName);return fn?Promise.resolve({result:fn.apply(null,__spreadArrays([el],args))}):Promise.reject(Error(functionName+" not exists"))},triggerEvent:function(el,type,detail){var vm=el.__vue__;return vm?vm.$trigger&&vm.$trigger(type,{},detail):el.fireEvent(type,{timeStamp:Date.now(),target:el,currentTarget:el},!1,{params:[{detail:detail}]}),Promise.resolve()}};function initNativeApi(){return Object.assign({},function(adapter){return{"Page.getElement":function(params){return adapter.querySelector(adapter.getDocument(params.pageId),params.selector)},"Page.getElements":function(params){return adapter.querySelectorAll(adapter.getDocument(params.pageId),params.selector)},"Page.getWindowProperties":function(params){return adapter.queryProperties(adapter.getWindow(params.pageId),params.names)}}}(NativeAdapter),function(adapter){var getEl=function(params){return adapter.getEl(params.elementId,params.pageId)};return{"Element.getElement":function(params){return adapter.querySelector(getEl(params),params.selector)},"Element.getElements":function(params){return adapter.querySelectorAll(getEl(params),params.selector)},"Element.getDOMProperties":function(params){return adapter.queryProperties(getEl(params),params.names)},"Element.getProperties":function(params){var el=getEl(params),ctx=el.__vue__||el.attr||{};return el.__vueParentComponent&&(ctx=Object.assign({},ctx,el.__vueParentComponent.attrs,el.__vueParentComponent.props)),adapter.queryProperties(ctx,params.names)},"Element.getOffset":function(params){return adapter.getOffset(getEl(params))},"Element.getAttributes":function(params){return adapter.queryAttributes(getEl(params),params.names)},"Element.getStyles":function(params){return adapter.queryStyles(getEl(params),params.names)},"Element.getHTML":function(params){return adapter.queryHTML(getEl(params),params.type)},"Element.tap":function(params){return adapter.dispatchTapEvent(getEl(params))},"Element.longpress":function(params){return adapter.dispatchLongpressEvent(getEl(params))},"Element.touchstart":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchstart",params)},"Element.touchmove":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchmove",params)},"Element.touchend":function(params){return adapter.dispatchTouchEvent(getEl(params),"touchend",params)},"Element.callFunction":function(params){return adapter.callFunction(getEl(params),params.functionName,params.args)},"Element.triggerEvent":function(params){return adapter.triggerEvent(getEl(params),params.type,params.detail)}}}(NativeAdapter))}var E=function(){};E.prototype={on:function(name,callback,ctx){var e=this.e||(this.e={});return(e[name]||(e[name]=[])).push({fn:callback,ctx:ctx}),this},once:function(name,callback,ctx){var self=this;function listener(){self.off(name,listener),callback.apply(ctx,arguments)}return listener._=callback,this.on(name,listener,ctx)},emit:function(name){for(var data=[].slice.call(arguments,1),evtArr=((this.e||(this.e={}))[name]||[]).slice(),i=0,len=evtArr.length;i=0;i--)if(evts[i].fn===callback||evts[i].fn._===callback){evts.splice(i,1);break}liveEvents=evts}return liveEvents.length?e[name]=liveEvents:delete e[name],this}};var Emitter=E;function initBridge(subscribeNamespace){var emitter=new Emitter;return{subscribe:function(event,callback,once){void 0===once&&(once=!1),emitter[once?"once":"on"](subscribeNamespace+"."+event,callback)},subscribeHandler:function(event,args,pageId){emitter.emit(subscribeNamespace+"."+event,args,pageId)}}}var extend=Object.assign,UniXServiceJSBridge=extend(initBridge("service"),{publishHandler:function(event,args,pageId){UniViewJSBridge.subscribeHandler(event,args,pageId)}}),UniXViewJSBridge=extend(initBridge("view"),{publishHandler:function(event,args,pageId){UniServiceJSBridge.subscribeHandler(event,args,pageId)}});if("undefined"==typeof UniServiceJSBridge&&"undefined"==typeof UniViewJSBridge){var __global__="undefined"==typeof globalThis?Function("return this")():globalThis;__global__.UniServiceJSBridge=UniXServiceJSBridge,__global__.UniViewJSBridge=UniXViewJSBridge}var Api={};Object.keys(App$1).forEach((function(method){Api["App."+method]=App$1[method]})),Object.keys(Page$1).forEach((function(method){Api["Page."+method]=Page$1[method]})),Object.keys(Element$1).forEach((function(method){Api["Element."+method]=Element$1[method]}));var NVueApi,fallback,socketTask,wsEndpoint=process.env.UNI_AUTOMATOR_WS_ENDPOINT;function send(data){socketTask.send({data:JSON.stringify(data)})}function onMessage(res){var _a=JSON.parse(res.data),id=_a.id,method=_a.method,params=_a.params,data={id:id},fn=Api[method];if(!fn){if(fallback){var result=fallback(id,method,params,data);if(!0===result)return;fn=result}if(!fn)return data.error={message:method+" unimplemented"},send(data)}try{fn(params,send).then((function(res){res&&(data.result=res)})).catch((function(err){data.error={message:err.message}})).finally((function(){send(data)}))}catch(err){data.error={message:err.message},send(data)}}fallback=function(id,method,params,data){var pageId=params.pageId,page=function(pageId){var pages=getCurrentPages();if(!pageId)return pages[pages.length-1];return pages.find((function(page){return page.$page.id===pageId}))}(pageId);return page?!page.$page.meta.isNVue?(UniServiceJSBridge.publishHandler("sendAutoMessage",{id:id,method:method,params:params},pageId),!0):(NVueApi||(NVueApi=initNativeApi()),NVueApi[method]):(data.error={message:"page["+pageId+"] not exists"},send(data),!0)},UniServiceJSBridge.subscribe("onAutoMessageReceive",(function(res){send(res)})),setTimeout((function(){if("undefined"!=typeof window&&(window.__uniapp_x_||window.__uniapp_x_postMessage))!function(data,callback){var _a,id=0;callback&&(id=postMessageId++,postMessageCallbacks[id]=callback);var message={data:{id:id,type:"automator",data:data}};console.log("postMessageToUniXWebView",message),(null===(_a=null===window||void 0===window?void 0:window.__uniapp_x_)||void 0===_a?void 0:_a.postMessage)?window.__uniapp_x_.postMessage(JSON.stringify(message)):(null===window||void 0===window?void 0:window.__uniapp_x_postMessage)&&window.__uniapp_x_postMessage({data:message})}({action:"ready"});else{if(wsEndpoint&&wsEndpoint.endsWith(":0000"))return;void 0===options&&(options={}),(socketTask=uni.connectSocket({url:options.wsEndpoint||wsEndpoint,complete:function(){}})).onMessage(onMessage),socketTask.onOpen((function(res){options.success&&options.success(),console.log("已开启自动化测试...")})),socketTask.onError((function(res){console.log("automator.onError",res)})),socketTask.onClose((function(){options.fail&&options.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))}var options}),500);export{send}; diff --git a/packages/uni-app-uts/lib/automator/ios/automator.js b/packages/uni-app-uts/lib/automator/ios/automator.js index 14e9645c43..a7ad2803cc 100644 --- a/packages/uni-app-uts/lib/automator/ios/automator.js +++ b/packages/uni-app-uts/lib/automator/ios/automator.js @@ -12,4 +12,4 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ -var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0)return I(e({method:r.replace("Socket","")},o[0])).then((function(e){return t(e)})).catch((function(e){return i(e)}));if(!uni[r])return i(Error("uni."+r+" not exists"));if(U(r))return t({result:uni[r].apply(uni,o)});var p=[Object.assign({},o[0]||{},{success:function(e){setTimeout((function(){t({result:e})}),"pageScrollTo"===r?350:0)},fail:function(e){i(Error(e.errMsg.replace(r+":fail ","")))}})];uni[r].apply(uni,p)}else(u=o[0].id,c=o[0].url,new Promise((function(e,t){var n=uni.connectSocket({url:c,success:function(){e({result:{errMsg:"connectSocket:ok"}})},fail:function(){t({result:{errMsg:"connectSocket:fail"}})}});M.set(u,{instance:n,isOpend:!1}),n.onOpen((function(e){M.get(u).isOpend=!0,M.get(u).openData=e}))}))).then((function(e){return t(e)})).catch((function(e){return i(e)}))}))},mockUniMethod:function(e){var t=e.method;if(!uni[t])throw Error("uni."+t+" not exists");if(!function(e){return!W.test(e)}(t))throw Error("You can't mock uni."+t);var n,r=e.result,i=e.functionDeclaration;return o(r)&&o(i)?(N[t]&&(uni[t]=N[t],delete N[t]),Promise.resolve()):(n=o(i)?U(t)?function(){return r}:function(e){setTimeout((function(){r.errMsg&&-1!==r.errMsg.indexOf(":fail")?e.fail&&e.fail(r):e.success&&e.success(r),e.complete&&e.complete(r)}),4)}:function(){for(var t=[],r=0;r"+te(ne(e,"inner"))+"":te(e.toString()):te(e.pureChildren.map((function(e){return e.toString()})).join(""))}var re={input:{input:function(e,t){e.setValue(t)}},textarea:{input:function(e,t){e.setValue(t)}},"scroll-view":{scrollTo:function(e,t,n){e.scrollTo(n)},scrollTop:function(e){return 0},scrollLeft:function(e){return 0},scrollWidth:function(e){return 0},scrollHeight:function(e){return 0}},swiper:{swipeTo:function(e,t){e.__vue__.current=t}},"movable-view":{moveTo:function(e,t,n){var r=e.__vue__;r.x=t,r.y=n}},switch:{tap:function(e){var t=e.__vue__;t.checked=!t.checked}},slider:{slideTo:function(e,t){e.__vue__.value=t}}};function oe(e){return X(e).body}var ie={getWindow:function(e){return oe(e)},getDocument:function(e){return oe(e)},getEl:function(e,t){var n=X(t).getRef(e);if(!n)throw Error("element destroyed");return n},getOffset:function(e){var t=e.__$weex__||e.ownerDocument.__$weex__;return new Promise((function(n){t.requireModule("dom").getComponentRect(e.ref,(function(e){e.result?n({left:e.size.left,top:e.size.top}):n({left:0,top:0})}))}))},querySelector:function(e,t){return Promise.resolve(G(Q(e,t)))},querySelectorAll:function(e,t){return Promise.resolve({elements:Q(e,t,[]).map((function(e){return G(e)}))})},queryProperties:function(e,t){var n=Z.find((function(n){return n.test(t,e)}));return n?n.call(e).then((function(e){return{properties:e}})):Promise.resolve({properties:t.map((function(t){return g(e,t)}))})},queryAttributes:function(e,t){var n=e.attr;return Promise.resolve({attributes:t.map((function(t){return"class"===t?(e.classList||[]).join(" "):String(n[t]||n[l(t)]||"")}))})},queryStyles:function(e,t){var n=e.style;return Promise.resolve({styles:t.map((function(e){return n[e]}))})},queryHTML:function(e,t){return Promise.resolve({html:ne(e,t)})},dispatchTapEvent:function(e){return e.fireEvent("click",{timeStamp:Date.now(),target:e,currentTarget:e},!0),Promise.resolve()},dispatchLongpressEvent:function(e){return e.fireEvent("longpress",{timeStamp:Date.now(),target:e,currentTarget:e},!0),Promise.resolve()},dispatchTouchEvent:function(e,t,n){return n||(n={}),n.touches||(n.touches=[]),n.changedTouches||(n.changedTouches=[]),n.touches.length||n.touches.push({identifier:Date.now(),target:e}),e.fireEvent(t,Object.assign({timeStamp:Date.now(),target:e,currentTarget:e},n),!0),Promise.resolve()},callFunction:function(e,n,r){var o=g(re,n);return o?Promise.resolve({result:o.apply(null,t([e],r))}):Promise.reject(Error(n+" not exists"))},triggerEvent:function(e,t,n){var r=e.__vue__;return r?r.$trigger&&r.$trigger(t,{},n):e.fireEvent(t,{timeStamp:Date.now(),target:e,currentTarget:e},!1,{params:[{detail:n}]}),Promise.resolve()}};function ue(){return Object.assign({},function(e){return{"Page.getElement":function(t){return e.querySelector(e.getDocument(t.pageId),t.selector)},"Page.getElements":function(t){return e.querySelectorAll(e.getDocument(t.pageId),t.selector)},"Page.getWindowProperties":function(t){return e.queryProperties(e.getWindow(t.pageId),t.names)}}}(ie),function(e){var t=function(t){return e.getEl(t.elementId,t.pageId)};return{"Element.getElement":function(n){return e.querySelector(t(n),n.selector)},"Element.getElements":function(n){return e.querySelectorAll(t(n),n.selector)},"Element.getDOMProperties":function(n){return e.queryProperties(t(n),n.names)},"Element.getProperties":function(n){var r=t(n),o=r.__vue__||r.attr||{};return r.__vueParentComponent&&(o=Object.assign({},o,r.__vueParentComponent.attrs,r.__vueParentComponent.props)),e.queryProperties(o,n.names)},"Element.getOffset":function(n){return e.getOffset(t(n))},"Element.getAttributes":function(n){return e.queryAttributes(t(n),n.names)},"Element.getStyles":function(n){return e.queryStyles(t(n),n.names)},"Element.getHTML":function(n){return e.queryHTML(t(n),n.type)},"Element.tap":function(n){return e.dispatchTapEvent(t(n))},"Element.longpress":function(n){return e.dispatchLongpressEvent(t(n))},"Element.touchstart":function(n){return e.dispatchTouchEvent(t(n),"touchstart",n)},"Element.touchmove":function(n){return e.dispatchTouchEvent(t(n),"touchmove",n)},"Element.touchend":function(n){return e.dispatchTouchEvent(t(n),"touchend",n)},"Element.callFunction":function(n){return e.callFunction(t(n),n.functionName,n.args)},"Element.triggerEvent":function(n){return e.triggerEvent(t(n),n.type,n.detail)}}}(ie))}var ce=function(){};ce.prototype={on:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var r=this;function o(){r.off(e,o),t.apply(n,arguments)}return o._=t,this.on(e,o,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),r=0,o=n.length;r=0;i--)if(r[i].fn===t||r[i].fn._===t){r.splice(i,1);break}o=r}return o.length?n[e]=o:delete n[e],this}};var ae=ce;function se(e){var t=new ae;return{subscribe:function(n,r,o){void 0===o&&(o=!1),t[o?"once":"on"](e+"."+n,r)},subscribeHandler:function(n,r,o){t.emit(e+"."+n,r,o)}}}var le=Object.assign,fe=le(se("service"),{publishHandler:function(e,t,n){UniViewJSBridge.subscribeHandler(e,t,n)}}),de=le(se("view"),{publishHandler:function(e,t,n){UniServiceJSBridge.subscribeHandler(e,t,n)}});if("undefined"==typeof UniServiceJSBridge&&"undefined"==typeof UniViewJSBridge){var pe="undefined"==typeof globalThis?Function("return this")():globalThis;pe.UniServiceJSBridge=fe,pe.UniViewJSBridge=de}var ge={};Object.keys(H).forEach((function(e){ge["App."+e]=H[e]})),Object.keys(j).forEach((function(e){ge["Page."+e]=j[e]})),Object.keys(V).forEach((function(e){ge["Element."+e]=V[e]}));var ve,he,me,_e=process.env.UNI_AUTOMATOR_WS_ENDPOINT;function Ee(e){me.send({data:JSON.stringify(e)})}function we(e){var t=JSON.parse(e.data),n=t.id,r=t.method,o=t.params,i={id:n},u=ge[r];if(!u){if(he){var c=he(n,r,o,i);if(!0===c)return;u=c}if(!u)return i.error={message:r+" unimplemented"},Ee(i)}try{u(o,Ee).then((function(e){e&&(i.result=e)})).catch((function(e){i.error={message:e.message}})).finally((function(){Ee(i)}))}catch(e){i.error={message:e.message},Ee(i)}}he=function(e,t,n,r){var o=n.pageId,i=function(e){var t=getCurrentPages();if(!e)return t[t.length-1];return t.find((function(t){return t.$page.id===e}))}(o);return i?!i.$page.meta.isNVue?(UniServiceJSBridge.publishHandler("sendAutoMessage",{id:e,method:t,params:n},o),!0):(ve||(ve=ue()),ve[t]):(r.error={message:"page["+o+"] not exists"},Ee(r),!0)},UniServiceJSBridge.subscribe("onAutoMessageReceive",(function(e){Ee(e)})),setTimeout((function(){if("undefined"!=typeof window&&window.__uniapp_x_)!function(e,t){var n=0;t&&(n=O++,$[n]=t);var r={data:{id:n,type:"automator",data:e}};console.log("postMessageToUniXWebView",r),"undefined"!=typeof window&&window.__uniapp_x_.postMessage(JSON.stringify(r))}({action:"ready"});else{if(_e&&_e.endsWith(":0000"))return;void 0===e&&(e={}),(me=uni.connectSocket({url:e.wsEndpoint||_e,complete:function(){}})).onMessage(we),me.onOpen((function(t){e.success&&e.success(),console.log("已开启自动化测试...")})),me.onError((function(e){console.log("automator.onError",e)})),me.onClose((function(){e.fail&&e.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))}var e}),500);var ye=Object.prototype.hasOwnProperty,Te=Array.isArray,Se=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;function Pe(e,t){if(Te(e))return e;if(t&&(n=t,r=e,ye.call(n,r)))return[e];var n,r,o=[];return e.replace(Se,(function(e,t,n,r){return o.push(n?r.replace(/\\(\\)?/g,"$1"):t||e),r})),o}function be(e){return"TEXT"===e.tagName||"TEXTAREA"===e.tagName}function xe(e){var t="";return e.childNodes.forEach((function(e){be(e)?t+=e.getAttribute("value"):t+=xe(e)})),t}function Oe(e){return e.startsWith("uni-")?e.replace("uni-",""):e}var $e=new Map;function Me(e){var t,n,r,o,i,u={elementId:(o=e,i=o._id,i||(i=Date.now()+"-"+Math.random(),o._id=i,$e.set(i,{id:i,element:o})),i),tagName:e.tagName.toLocaleLowerCase().replace("uni-","")},c=e.__vueParentComponent;return c&&((null===(t=c.ctx)||void 0===t?void 0:t.$el)!==e||(null===(r=null===(n=c.proxy)||void 0===n?void 0:n.$options)||void 0===r?void 0:r.rootElement)||(u.nodeId=function(e){if(e._$weex)return e._uid;if(e._$id)return e._$id;if(e.uid)return e.uid;var t=function(e){for(var t=e.$parent;t;){if(t._$id)return t;t=t.$parent}}(e);if(!e.$parent)return"-1";var n=e.$vnode,r=n.context;return r&&r!==t&&r._$id?r._$id+";"+t._$id+","+n.data.attrs._i:t._$id+","+n.data.attrs._i}(c))),"video"===u.tagName&&(u.videoId=u.nodeId),u}var Ie={input:{input:function(e,t){var n=new UniInputEvent("input",{detail:{value:t}});n.detail.value=t,e.dispatchEvent("input",n)}},textarea:{input:function(e,t){var n=new UniInputEvent("input",{detail:{value:t}});n.detail.value=t,e.dispatchEvent("input",n)}},"scroll-view":{scrollTo:function(e,t,n){e.scrollLeft=t,e.scrollTop=n},scrollTop:function(e){return e.scrollTop},scrollLeft:function(e){return e.scrollLeft},scrollWidth:function(e){return e.scrollWidth},scrollHeight:function(e){return e.scrollHeight}},swiper:{swipeTo:function(e,t){e.setAttribute("current",t)}},"movable-view":{moveTo:function(e,t,n){e.__vue__._animationTo(t,n)}},switch:{tap:function(e){e.click()}},slider:{slideTo:function(e,t){e.setAttribute("value",t)}}};function Ce(e){var t=getCurrentPages().find((function(t){return t.$page.id===e}));if(!t)throw Error("page["+e+"] not found");return t.$el.parentNode}function Ae(e){return e.map((function(e){return function(e){return new UniTouch(e)}(e)}))}var ke,qe={getWindow:function(e){var t=Ce(e);return 1===t.childNodes.length?t.childNodes[0]:t},getDocument:function(e){return Ce(e)},getEl:function(e){var t=$e.get(e);if(!t)throw Error("element destroyed");return t.element},getOffset:function(e){return Promise.resolve({left:e.offsetLeft,top:e.offsetTop})},querySelector:function(e,t){return"page"===(t=Oe(t))&&(t="body"),Promise.resolve(Me(e.querySelector(t)))},querySelectorAll:function(e,t){t=Oe(t);var n=[],r=e.querySelectorAll(t);return[].forEach.call(r,(function(e){try{n.push(Me(e))}catch(e){}})),Promise.resolve({elements:n})},queryProperties:function(e,t){return Promise.resolve({properties:t.map((function(t){return"innerText"==t?be(e)?e.getAttribute("value"):xe(e):"value"==t?e.getAnyAttribute("value"):"offsetWidth"==t?e.offsetWidth:"offsetHeight"==t?e.offsetHeight:"document.documentElement.scrollWidth"===t?e.scrollWidth:"document.documentElement.scrollHeight"===t?e.scrollHeight:"document.documentElement.scrollTop"===t?e.scrollTop:e.getAttribute(t)||e[t](ke||(n=["Element.getDOMProperties not support ",""],r=["Element.getDOMProperties not support ",""],Object.defineProperty?Object.defineProperty(n,"raw",{value:r}):n.raw=r,ke=n),t);var n,r}))})},queryAttributes:function(e,t){return Promise.resolve({attributes:t.map((function(t){return String(e.getAnyAttribute(t))}))})},queryStyles:function(e,t){var n=e._style;return Promise.resolve({styles:t.map((function(e){return n[e]}))})},queryHTML:function(e,t){return Promise.resolve({html:(n="outer"===t?e.outerHTML:e.innerHTML,n.replace(/\n/g,"").replace(/(]*>)(]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(e){return-1":""===e?"":0!==e.indexOf("0)return I(e({method:r.replace("Socket","")},o[0])).then((function(e){return t(e)})).catch((function(e){return i(e)}));if(!uni[r])return i(Error("uni."+r+" not exists"));if(U(r))return t({result:uni[r].apply(uni,o)});var p=[Object.assign({},o[0]||{},{success:function(e){setTimeout((function(){t({result:e})}),"pageScrollTo"===r?350:0)},fail:function(e){i(Error(e.errMsg.replace(r+":fail ","")))}})];uni[r].apply(uni,p)}else(u=o[0].id,a=o[0].url,new Promise((function(e,t){var n=uni.connectSocket({url:a,success:function(){e({result:{errMsg:"connectSocket:ok"}})},fail:function(){t({result:{errMsg:"connectSocket:fail"}})}});M.set(u,{instance:n,isOpend:!1}),n.onOpen((function(e){M.get(u).isOpend=!0,M.get(u).openData=e}))}))).then((function(e){return t(e)})).catch((function(e){return i(e)}))}))},mockUniMethod:function(e){var t=e.method;if(!uni[t])throw Error("uni."+t+" not exists");if(!function(e){return!W.test(e)}(t))throw Error("You can't mock uni."+t);var n,r=e.result,i=e.functionDeclaration;return o(r)&&o(i)?(N[t]&&(uni[t]=N[t],delete N[t]),Promise.resolve()):(n=o(i)?U(t)?function(){return r}:function(e){setTimeout((function(){r.errMsg&&-1!==r.errMsg.indexOf(":fail")?e.fail&&e.fail(r):e.success&&e.success(r),e.complete&&e.complete(r)}),4)}:function(){for(var t=[],r=0;r"+te(ne(e,"inner"))+"":te(e.toString()):te(e.pureChildren.map((function(e){return e.toString()})).join(""))}var re={input:{input:function(e,t){e.setValue(t)}},textarea:{input:function(e,t){e.setValue(t)}},"scroll-view":{scrollTo:function(e,t,n){e.scrollTo(n)},scrollTop:function(e){return 0},scrollLeft:function(e){return 0},scrollWidth:function(e){return 0},scrollHeight:function(e){return 0}},swiper:{swipeTo:function(e,t){e.__vue__.current=t}},"movable-view":{moveTo:function(e,t,n){var r=e.__vue__;r.x=t,r.y=n}},switch:{tap:function(e){var t=e.__vue__;t.checked=!t.checked}},slider:{slideTo:function(e,t){e.__vue__.value=t}}};function oe(e){return X(e).body}var ie={getWindow:function(e){return oe(e)},getDocument:function(e){return oe(e)},getEl:function(e,t){var n=X(t).getRef(e);if(!n)throw Error("element destroyed");return n},getOffset:function(e){var t=e.__$weex__||e.ownerDocument.__$weex__;return new Promise((function(n){t.requireModule("dom").getComponentRect(e.ref,(function(e){e.result?n({left:e.size.left,top:e.size.top}):n({left:0,top:0})}))}))},querySelector:function(e,t){return Promise.resolve(G(Q(e,t)))},querySelectorAll:function(e,t){return Promise.resolve({elements:Q(e,t,[]).map((function(e){return G(e)}))})},queryProperties:function(e,t){var n=Z.find((function(n){return n.test(t,e)}));return n?n.call(e).then((function(e){return{properties:e}})):Promise.resolve({properties:t.map((function(t){return g(e,t)}))})},queryAttributes:function(e,t){var n=e.attr;return Promise.resolve({attributes:t.map((function(t){return"class"===t?(e.classList||[]).join(" "):String(n[t]||n[l(t)]||"")}))})},queryStyles:function(e,t){var n=e.style;return Promise.resolve({styles:t.map((function(e){return n[e]}))})},queryHTML:function(e,t){return Promise.resolve({html:ne(e,t)})},dispatchTapEvent:function(e){return e.fireEvent("click",{timeStamp:Date.now(),target:e,currentTarget:e},!0),Promise.resolve()},dispatchLongpressEvent:function(e){return e.fireEvent("longpress",{timeStamp:Date.now(),target:e,currentTarget:e},!0),Promise.resolve()},dispatchTouchEvent:function(e,t,n){return n||(n={}),n.touches||(n.touches=[]),n.changedTouches||(n.changedTouches=[]),n.touches.length||n.touches.push({identifier:Date.now(),target:e}),e.fireEvent(t,Object.assign({timeStamp:Date.now(),target:e,currentTarget:e},n),!0),Promise.resolve()},callFunction:function(e,n,r){var o=g(re,n);return o?Promise.resolve({result:o.apply(null,t([e],r))}):Promise.reject(Error(n+" not exists"))},triggerEvent:function(e,t,n){var r=e.__vue__;return r?r.$trigger&&r.$trigger(t,{},n):e.fireEvent(t,{timeStamp:Date.now(),target:e,currentTarget:e},!1,{params:[{detail:n}]}),Promise.resolve()}};function ue(){return Object.assign({},function(e){return{"Page.getElement":function(t){return e.querySelector(e.getDocument(t.pageId),t.selector)},"Page.getElements":function(t){return e.querySelectorAll(e.getDocument(t.pageId),t.selector)},"Page.getWindowProperties":function(t){return e.queryProperties(e.getWindow(t.pageId),t.names)}}}(ie),function(e){var t=function(t){return e.getEl(t.elementId,t.pageId)};return{"Element.getElement":function(n){return e.querySelector(t(n),n.selector)},"Element.getElements":function(n){return e.querySelectorAll(t(n),n.selector)},"Element.getDOMProperties":function(n){return e.queryProperties(t(n),n.names)},"Element.getProperties":function(n){var r=t(n),o=r.__vue__||r.attr||{};return r.__vueParentComponent&&(o=Object.assign({},o,r.__vueParentComponent.attrs,r.__vueParentComponent.props)),e.queryProperties(o,n.names)},"Element.getOffset":function(n){return e.getOffset(t(n))},"Element.getAttributes":function(n){return e.queryAttributes(t(n),n.names)},"Element.getStyles":function(n){return e.queryStyles(t(n),n.names)},"Element.getHTML":function(n){return e.queryHTML(t(n),n.type)},"Element.tap":function(n){return e.dispatchTapEvent(t(n))},"Element.longpress":function(n){return e.dispatchLongpressEvent(t(n))},"Element.touchstart":function(n){return e.dispatchTouchEvent(t(n),"touchstart",n)},"Element.touchmove":function(n){return e.dispatchTouchEvent(t(n),"touchmove",n)},"Element.touchend":function(n){return e.dispatchTouchEvent(t(n),"touchend",n)},"Element.callFunction":function(n){return e.callFunction(t(n),n.functionName,n.args)},"Element.triggerEvent":function(n){return e.triggerEvent(t(n),n.type,n.detail)}}}(ie))}var ae=function(){};ae.prototype={on:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var r=this;function o(){r.off(e,o),t.apply(n,arguments)}return o._=t,this.on(e,o,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),r=0,o=n.length;r=0;i--)if(r[i].fn===t||r[i].fn._===t){r.splice(i,1);break}o=r}return o.length?n[e]=o:delete n[e],this}};var ce=ae;function se(e){var t=new ce;return{subscribe:function(n,r,o){void 0===o&&(o=!1),t[o?"once":"on"](e+"."+n,r)},subscribeHandler:function(n,r,o){t.emit(e+"."+n,r,o)}}}var le=Object.assign,fe=le(se("service"),{publishHandler:function(e,t,n){UniViewJSBridge.subscribeHandler(e,t,n)}}),de=le(se("view"),{publishHandler:function(e,t,n){UniServiceJSBridge.subscribeHandler(e,t,n)}});if("undefined"==typeof UniServiceJSBridge&&"undefined"==typeof UniViewJSBridge){var pe="undefined"==typeof globalThis?Function("return this")():globalThis;pe.UniServiceJSBridge=fe,pe.UniViewJSBridge=de}var ge={};Object.keys(H).forEach((function(e){ge["App."+e]=H[e]})),Object.keys(j).forEach((function(e){ge["Page."+e]=j[e]})),Object.keys(V).forEach((function(e){ge["Element."+e]=V[e]}));var ve,he,me,_e=process.env.UNI_AUTOMATOR_WS_ENDPOINT;function Ee(e){me.send({data:JSON.stringify(e)})}function we(e){var t=JSON.parse(e.data),n=t.id,r=t.method,o=t.params,i={id:n},u=ge[r];if(!u){if(he){var a=he(n,r,o,i);if(!0===a)return;u=a}if(!u)return i.error={message:r+" unimplemented"},Ee(i)}try{u(o,Ee).then((function(e){e&&(i.result=e)})).catch((function(e){i.error={message:e.message}})).finally((function(){Ee(i)}))}catch(e){i.error={message:e.message},Ee(i)}}he=function(e,t,n,r){var o=n.pageId,i=function(e){var t=getCurrentPages();if(!e)return t[t.length-1];return t.find((function(t){return t.$page.id===e}))}(o);return i?!i.$page.meta.isNVue?(UniServiceJSBridge.publishHandler("sendAutoMessage",{id:e,method:t,params:n},o),!0):(ve||(ve=ue()),ve[t]):(r.error={message:"page["+o+"] not exists"},Ee(r),!0)},UniServiceJSBridge.subscribe("onAutoMessageReceive",(function(e){Ee(e)})),setTimeout((function(){if("undefined"!=typeof window&&(window.__uniapp_x_||window.__uniapp_x_postMessage))!function(e,t){var n,r=0;t&&(r=O++,$[r]=t);var o={data:{id:r,type:"automator",data:e}};console.log("postMessageToUniXWebView",o),(null===(n=null===window||void 0===window?void 0:window.__uniapp_x_)||void 0===n?void 0:n.postMessage)?window.__uniapp_x_.postMessage(JSON.stringify(o)):(null===window||void 0===window?void 0:window.__uniapp_x_postMessage)&&window.__uniapp_x_postMessage({data:o})}({action:"ready"});else{if(_e&&_e.endsWith(":0000"))return;void 0===e&&(e={}),(me=uni.connectSocket({url:e.wsEndpoint||_e,complete:function(){}})).onMessage(we),me.onOpen((function(t){e.success&&e.success(),console.log("已开启自动化测试...")})),me.onError((function(e){console.log("automator.onError",e)})),me.onClose((function(){e.fail&&e.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))}var e}),500);var ye=Object.prototype.hasOwnProperty,Te=Array.isArray,Se=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;function Pe(e,t){if(Te(e))return e;if(t&&(n=t,r=e,ye.call(n,r)))return[e];var n,r,o=[];return e.replace(Se,(function(e,t,n,r){return o.push(n?r.replace(/\\(\\)?/g,"$1"):t||e),r})),o}function be(e){return"TEXT"===e.tagName||"TEXTAREA"===e.tagName}function xe(e){var t="";return e.childNodes.forEach((function(e){be(e)?t+=e.getAttribute("value"):t+=xe(e)})),t}function Oe(e){return e.startsWith("uni-")?e.replace("uni-",""):e}var $e=new Map;function Me(e){var t,n,r,o,i,u={elementId:(o=e,i=o._id,i||(i=Date.now()+"-"+Math.random(),o._id=i,$e.set(i,{id:i,element:o})),i),tagName:e.tagName.toLocaleLowerCase().replace("uni-","")},a=e.__vueParentComponent;return a&&((null===(t=a.ctx)||void 0===t?void 0:t.$el)!==e||(null===(r=null===(n=a.proxy)||void 0===n?void 0:n.$options)||void 0===r?void 0:r.rootElement)||(u.nodeId=function(e){if(e._$weex)return e._uid;if(e._$id)return e._$id;if(e.uid)return e.uid;var t=function(e){for(var t=e.$parent;t;){if(t._$id)return t;t=t.$parent}}(e);if(!e.$parent)return"-1";var n=e.$vnode,r=n.context;return r&&r!==t&&r._$id?r._$id+";"+t._$id+","+n.data.attrs._i:t._$id+","+n.data.attrs._i}(a))),"video"===u.tagName&&(u.videoId=u.nodeId),u}var Ie={input:{input:function(e,t){var n=new UniInputEvent("input",{detail:{value:t}});n.detail.value=t,e.dispatchEvent("input",n)}},textarea:{input:function(e,t){var n=new UniInputEvent("input",{detail:{value:t}});n.detail.value=t,e.dispatchEvent("input",n)}},"scroll-view":{scrollTo:function(e,t,n){e.scrollLeft=t,e.scrollTop=n},scrollTop:function(e){return e.scrollTop},scrollLeft:function(e){return e.scrollLeft},scrollWidth:function(e){return e.scrollWidth},scrollHeight:function(e){return e.scrollHeight}},swiper:{swipeTo:function(e,t){e.setAttribute("current",t)}},"movable-view":{moveTo:function(e,t,n){e.__vue__._animationTo(t,n)}},switch:{tap:function(e){e.click()}},slider:{slideTo:function(e,t){e.setAttribute("value",t)}}};function Ce(e){var t=getCurrentPages().find((function(t){return t.$page.id===e}));if(!t)throw Error("page["+e+"] not found");return t.$el.parentNode}function Ae(e){return e.map((function(e){return function(e){return new UniTouch(e)}(e)}))}var ke,qe={getWindow:function(e){var t=Ce(e);return 1===t.childNodes.length?t.childNodes[0]:t},getDocument:function(e){return Ce(e)},getEl:function(e){var t=$e.get(e);if(!t)throw Error("element destroyed");return t.element},getOffset:function(e){return Promise.resolve({left:e.offsetLeft,top:e.offsetTop})},querySelector:function(e,t){return"page"===(t=Oe(t))&&(t="body"),Promise.resolve(Me(e.querySelector(t)))},querySelectorAll:function(e,t){t=Oe(t);var n=[],r=e.querySelectorAll(t);return[].forEach.call(r,(function(e){try{n.push(Me(e))}catch(e){}})),Promise.resolve({elements:n})},queryProperties:function(e,t){return Promise.resolve({properties:t.map((function(t){return"innerText"==t?be(e)?e.getAttribute("value"):xe(e):"value"==t?e.getAnyAttribute("value"):"offsetWidth"==t?e.offsetWidth:"offsetHeight"==t?e.offsetHeight:"document.documentElement.scrollWidth"===t?e.scrollWidth:"document.documentElement.scrollHeight"===t?e.scrollHeight:"document.documentElement.scrollTop"===t?e.scrollTop:e.getAttribute(t)||e[t](ke||(n=["Element.getDOMProperties not support ",""],r=["Element.getDOMProperties not support ",""],Object.defineProperty?Object.defineProperty(n,"raw",{value:r}):n.raw=r,ke=n),t);var n,r}))})},queryAttributes:function(e,t){return Promise.resolve({attributes:t.map((function(t){return String(e.getAnyAttribute(t))}))})},queryStyles:function(e,t){var n=e._style;return Promise.resolve({styles:t.map((function(e){return n[e]}))})},queryHTML:function(e,t){return Promise.resolve({html:(n="outer"===t?e.outerHTML:e.innerHTML,n.replace(/\n/g,"").replace(/(]*>)(]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(e){return-1":""===e?"":0!==e.indexOf("]*>)(]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(e){return-1":""===e?"":0!==e.indexOf("0)return R(e({method:r.replace("Socket","")},o[0])).then((function(e){return n(e)})).catch((function(e){return i(e)}));if(!uni[r])return i(Error("uni."+r+" not exists"));if(G(r))return n({result:uni[r].apply(uni,o)});var p=[Object.assign({},o[0]||{},{success:function(e){setTimeout((function(){n({result:e})}),"pageScrollTo"===r?350:0)},fail:function(e){i(Error(e.errMsg.replace(r+":fail ","")))}})];uni[r].apply(uni,p)}else(u=o[0].id,a=o[0].url,new Promise((function(e,n){var t=uni.connectSocket({url:a,success:function(){e({result:{errMsg:"connectSocket:ok"}})},fail:function(){n({result:{errMsg:"connectSocket:fail"}})}});L.set(u,{instance:t,isOpend:!1}),t.onOpen((function(e){L.get(u).isOpend=!0,L.get(u).openData=e}))}))).then((function(e){return n(e)})).catch((function(e){return i(e)}))}))},mockUniMethod:function(e){var n=e.method;if(!uni[n])throw Error("uni."+n+" not exists");if(!function(e){return!z.test(e)}(n))throw Error("You can't mock uni."+n);var t,r=e.result,o=e.functionDeclaration;return s(r)&&s(o)?(F[n]&&(uni[n]=F[n],delete F[n]),Promise.resolve()):(t=s(o)?G(n)?function(){return r}:function(e){setTimeout((function(){r.errMsg&&-1!==r.errMsg.indexOf(":fail")?e.fail&&e.fail(r):e.success&&e.success(r),e.complete&&e.complete(r)}),4)}:function(){for(var n=[],r=0;r]*>)(]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(e){return-1":""===e?"":0!==e.indexOf("0)return R(e({method:r.replace("Socket","")},o[0])).then((function(e){return n(e)})).catch((function(e){return i(e)}));if(!uni[r])return i(Error("uni."+r+" not exists"));if(G(r))return n({result:uni[r].apply(uni,o)});var p=[Object.assign({},o[0]||{},{success:function(e){setTimeout((function(){n({result:e})}),"pageScrollTo"===r?350:0)},fail:function(e){i(Error(e.errMsg.replace(r+":fail ","")))}})];uni[r].apply(uni,p)}else(u=o[0].id,a=o[0].url,new Promise((function(e,n){var t=uni.connectSocket({url:a,success:function(){e({result:{errMsg:"connectSocket:ok"}})},fail:function(){n({result:{errMsg:"connectSocket:fail"}})}});L.set(u,{instance:t,isOpend:!1}),t.onOpen((function(e){L.get(u).isOpend=!0,L.get(u).openData=e}))}))).then((function(e){return n(e)})).catch((function(e){return i(e)}))}))},mockUniMethod:function(e){var n=e.method;if(!uni[n])throw Error("uni."+n+" not exists");if(!function(e){return!z.test(e)}(n))throw Error("You can't mock uni."+n);var t,r=e.result,o=e.functionDeclaration;return s(r)&&s(o)?(F[n]&&(uni[n]=F[n],delete F[n]),Promise.resolve()):(t=s(o)?G(n)?function(){return r}:function(e){setTimeout((function(){r.errMsg&&-1!==r.errMsg.indexOf(":fail")?e.fail&&e.fail(r):e.success&&e.success(r),e.complete&&e.complete(r)}),4)}:function(){for(var n=[],r=0;r0)return firstSocketTaskEmitter(__assign({method:method.replace("Socket","")},args[0])).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}));if(!uni[method])return reject(Error("uni."+method+" not exists"));if(isSyncApi(method))return resolve({result:uni[method].apply(uni,args)});var params=[Object.assign({},args[0]||{},{success:function(result){setTimeout((function(){resolve({result:result})}),"pageScrollTo"===method?350:0)},fail:function(res){reject(Error(res.errMsg.replace(method+":fail ","")))}})];uni[method].apply(uni,params)}else(id=args[0].id,url=args[0].url,new Promise((function(resolve,reject){var socketTask=uni.connectSocket({url:url,success:function(){resolve({result:{errMsg:"connectSocket:ok"}})},fail:function(){reject({result:{errMsg:"connectSocket:fail"}})}});socketInstanceMap.set(id,{instance:socketTask,isOpend:!1}),socketTask.onOpen((function(data){socketInstanceMap.get(id).isOpend=!0,socketInstanceMap.get(id).openData=data}))}))).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}))}))},mockUniMethod:function(params){var method=params.method;if(!uni[method])throw Error("uni."+method+" not exists");if(!function(method){return!MOCK_API_BLACKLIST_RE.test(method)}(method))throw Error("You can't mock uni."+method);var mockFn,result=params.result,functionDeclaration=params.functionDeclaration;return isUndef(result)&&isUndef(functionDeclaration)?(originUni[method]&&(uni[method]=originUni[method],delete originUni[method]),Promise.resolve()):(mockFn=isUndef(functionDeclaration)?isSyncApi(method)?function(){return result}:function(params){setTimeout((function(){result.errMsg&&-1!==result.errMsg.indexOf(":fail")?params.fail&¶ms.fail(result):params.success&¶ms.success(result),params.complete&¶ms.complete(result)}),4)}:function(){for(var args=[],_i=0;_i0)return firstSocketTaskEmitter(__assign({method:method.replace("Socket","")},args[0])).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}));if(!uni[method])return reject(Error("uni."+method+" not exists"));if(isSyncApi(method))return resolve({result:uni[method].apply(uni,args)});var params=[Object.assign({},args[0]||{},{success:function(result){setTimeout((function(){resolve({result:result})}),"pageScrollTo"===method?350:0)},fail:function(res){reject(Error(res.errMsg.replace(method+":fail ","")))}})];uni[method].apply(uni,params)}else(id=args[0].id,url=args[0].url,new Promise((function(resolve,reject){var socketTask=uni.connectSocket({url:url,success:function(){resolve({result:{errMsg:"connectSocket:ok"}})},fail:function(){reject({result:{errMsg:"connectSocket:fail"}})}});socketInstanceMap.set(id,{instance:socketTask,isOpend:!1}),socketTask.onOpen((function(data){socketInstanceMap.get(id).isOpend=!0,socketInstanceMap.get(id).openData=data}))}))).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}))}))},mockUniMethod:function(params){var method=params.method;if(!uni[method])throw Error("uni."+method+" not exists");if(!function(method){return!MOCK_API_BLACKLIST_RE.test(method)}(method))throw Error("You can't mock uni."+method);var mockFn,result=params.result,functionDeclaration=params.functionDeclaration;return isUndef(result)&&isUndef(functionDeclaration)?(originUni[method]&&(uni[method]=originUni[method],delete originUni[method]),Promise.resolve()):(mockFn=isUndef(functionDeclaration)?isSyncApi(method)?function(){return result}:function(params){setTimeout((function(){result.errMsg&&-1!==result.errMsg.indexOf(":fail")?params.fail&¶ms.fail(result):params.success&¶ms.success(result),params.complete&¶ms.complete(result)}),4)}:function(){for(var args=[],_i=0;_i0)return firstSocketTaskEmitter(__assign({method:method.replace("Socket","")},args[0])).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}));if(!uni[method])return reject(Error("uni."+method+" not exists"));if(isSyncApi(method))return resolve({result:uni[method].apply(uni,args)});var params=[Object.assign({},args[0]||{},{success:function(result){setTimeout((function(){resolve({result:result})}),"pageScrollTo"===method?350:0)},fail:function(res){reject(Error(res.errMsg.replace(method+":fail ","")))}})];uni[method].apply(uni,params)}else(id=args[0].id,url=args[0].url,new Promise((function(resolve,reject){var socketTask=uni.connectSocket({url:url,success:function(){resolve({result:{errMsg:"connectSocket:ok"}})},fail:function(){reject({result:{errMsg:"connectSocket:fail"}})}});socketInstanceMap.set(id,{instance:socketTask,isOpend:!1}),socketTask.onOpen((function(data){socketInstanceMap.get(id).isOpend=!0,socketInstanceMap.get(id).openData=data}))}))).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}))}))},mockUniMethod:function(params){var method=params.method;if(!uni[method])throw Error("uni."+method+" not exists");if(!function(method){return!MOCK_API_BLACKLIST_RE.test(method)}(method))throw Error("You can't mock uni."+method);var mockFn,result=params.result,functionDeclaration=params.functionDeclaration;return isUndef(result)&&isUndef(functionDeclaration)?(originUni[method]&&(uni[method]=originUni[method],delete originUni[method]),Promise.resolve()):(mockFn=isUndef(functionDeclaration)?isSyncApi(method)?function(){return result}:function(params){setTimeout((function(){result.errMsg&&-1!==result.errMsg.indexOf(":fail")?params.fail&¶ms.fail(result):params.success&¶ms.success(result),params.complete&¶ms.complete(result)}),4)}:function(){for(var args=[],_i=0;_i0)return firstSocketTaskEmitter(__assign({method:method.replace("Socket","")},args[0])).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}));if(!uni[method])return reject(Error("uni."+method+" not exists"));if(isSyncApi(method))return resolve({result:uni[method].apply(uni,args)});var params=[Object.assign({},args[0]||{},{success:function(result){setTimeout((function(){resolve({result:result})}),"pageScrollTo"===method?350:0)},fail:function(res){reject(Error(res.errMsg.replace(method+":fail ","")))}})];uni[method].apply(uni,params)}else(id=args[0].id,url=args[0].url,new Promise((function(resolve,reject){var socketTask=uni.connectSocket({url:url,success:function(){resolve({result:{errMsg:"connectSocket:ok"}})},fail:function(){reject({result:{errMsg:"connectSocket:fail"}})}});socketInstanceMap.set(id,{instance:socketTask,isOpend:!1}),socketTask.onOpen((function(data){socketInstanceMap.get(id).isOpend=!0,socketInstanceMap.get(id).openData=data}))}))).then((function(res){return resolve(res)})).catch((function(err){return reject(err)}))}))},mockUniMethod:function(params){var method=params.method;if(!uni[method])throw Error("uni."+method+" not exists");if(!function(method){return!MOCK_API_BLACKLIST_RE.test(method)}(method))throw Error("You can't mock uni."+method);var mockFn,result=params.result,functionDeclaration=params.functionDeclaration;return isUndef(result)&&isUndef(functionDeclaration)?(originUni[method]&&(uni[method]=originUni[method],delete originUni[method]),Promise.resolve()):(mockFn=isUndef(functionDeclaration)?isSyncApi(method)?function(){return result}:function(params){setTimeout((function(){result.errMsg&&-1!==result.errMsg.indexOf(":fail")?params.fail&¶ms.fail(result):params.success&¶ms.success(result),params.complete&¶ms.complete(result)}),4)}:function(){for(var args=[],_i=0;_i