1***@qq.com
1***@qq.com
  • 发布:2020-09-23 11:28
  • 更新:2021-05-28 16:49
  • 阅读:970

执行自动化测试的时候,报 TypeError: Cannot read property '$' of undefined

分类:uni-app

根据文档:https://uniapp.dcloud.net.cn/collocation/auto/quick-start

执行:npm run test:ios

报错如下:

● pages/index/index.vue › 测试

TypeError: Cannot read property '$' of undefined  

   8 |  
   9 |  it('测试', async () => {  
> 10 |       expect(await page.$('.pTitle').text().toBe('Hello'))  
     |                         ^  
  11 |  })  
  12 |  
  13 | })  

  at Object.<anonymous> (src/pages/index/index.test.js:10:21)  

测试代码是:

describe('pages/index/index.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/index/index.vue')
await page.waitFor(1000)
})

it('测试', async () => {
expect(await page.$('.pTitle').text().toBe('Hello'))
})

})

2020-09-23 11:28 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

测试其他端是否正常?

模拟器是否启动?

8***@qq.com

8***@qq.com

请问解决了吗 我的也是这样 项目是可以启动的

DCloud_UNI_LXH

DCloud_UNI_LXH

是否执行了npm install puppeteer

  • 5***@qq.com

    我的也是这样 puppeteer 14.0.0 版本

    2023-03-14 14:24

  • DCloud_UNI_LXH

    回复 5***@qq.com: 使用这个插件是否可以运行 https://ext.dcloud.net.cn/plugin?id=5708

    2023-03-14 17:35

该问题目前已经被锁定, 无法添加新回复