自己的问题
一个测试脚本中mock2次组件的返回结果,第二次报‘’小程序接口出错,错误代码500‘’?调用的js: wx.showActionSheet({ itemList: that.data.empList, success: function (res) { var empListIdS = that.data.empListIdS, bind_Id = empListIdS[res.tapIndex]; wx.showModal({ content: '您确定要切换工号为' + that.data.empList[res.tapIndex] + '为技师吗?', success: function (res1) { console.log(res1) if (res1.confirm) { that.setData({ bind_Id: bind_Id }); that.getEmplInfo(); } } }); } }) } 脚本中的第一个mock: let setshowModal_list = ''; let showActionSheet_content = ''; await miniProgram.exposeFunction('setshowModal', function (item) { setshowModal_list = item }) await miniProgram.exposeFunction('setshowActionSheet', function (item1) { showActionSheet_content = item1 }) await miniProgram.mockWxMethod('showActionSheet', function (obj) { setshowActionSheet(obj.itemList) return { tapIndex: 1 } }) await miniProgram.mockWxMethod('showModal', function (obj){ setshowModal(obj.content) return{confirm:true, cancel:false} }) await miniProgram.restoreWxMethod('showActionSheet') await miniProgram.restoreWxMethod('showModal') await employee_page.waitFor(3000) 脚本中的第二个mock: let setshowModal_performancesum = ''; let showActionSheet_list_performancesum= ''; await miniProgram.exposeFunction('setshowModal_performancesum', function (content) { setshowModal_performancesum = content }) await miniProgram.exposeFunction('setshowActionSheet_per', function (itemList) { showActionSheet_list_performancesum = itemList }) await miniProgram.mockWxMethod('showActionSheet', function (obj1) { console.log('调用showActionSheet组件返回列表',obj1.itemList) setshowActionSheet_per(obj1.itemList) return { tapIndex: 1 } }) await miniProgram.mockWxMethod('showModal', function (obj) { console.log('调用showModal组件0000000000000000000000000000000') setshowModal_performancesum(obj.content) return{confirm:true, cancel:false} }) await miniProgram.restoreWxMethod('showActionSheet') await miniProgram.restoreWxMethod('showModal') 第二个mock方法内的log信息均未打印,showActionSheet_list_performancesum值正常打印,setshowModal_performancesum的值为'小程序接口出错, 错误代码500';第一次mock正常执行
2021-09-08好像是因为元素数据没加载出来,取到了骨架框的值,加入等待之后就可以正常定位了
调用mockWxMethod后元素定位不准确?最开始元素定位正常,后来因为要操作原生组件,调用 // await miniProgram.mockWxMethod('showActionSheet', { // itemList: [ // "444(当前)", // "85857" // ], // tapIndex:1, // cancel:false // }) 然后调用restoreWxMethod消除,后面就出现了元素定位不准确的问题,重复执行以下代码const pageHead = await employee_page.$('.pageHead') const bannerBox = await pageHead.$('.bannerBox') const store_name = await bannerBox.$('.store-name') await employee_page.waitFor(2000) //await miniProgram.restoreWxMethod('showActionSheet') console.log(await store_name.attribute('class')) const icons = await store_name.$$('.van-icon') console.log(await store_name.text()) console.log(await icons.length) console.log('Cccccccccccccccccc') const icon1 = await icons[0] console.log(await icon1.attribute('class')) console.log('===========================================') const texts = await store_name.$$('text') console.log(await texts.length) const text1 = await texts[0] console.log(await text1.attribute('class')) console.log(await text1.wxml()) 会得到不同的结果,如图 [图片][图片]
2021-09-06找到方法了,宁波泰怡然所在的class中选择一种值进行定位如text-xl就能定位到宁波泰怡然所在class,定位和邦店所在的元素时在margin-bottom-xl下生成同名class的列表,之后操作列表下表就能定位了
使用原生SDK做小程序自动化时定位元素不准确?[图片] 小程序定位元素的情况如图
2021-08-18