javascript - Appium 错误处理不起作用
问题描述
我是appium的新手,所以可能会做错事。
我对使用 wdio 和 jasmine 的 appium 有疑问
it('wtf', (done) => {
client.init().element('someName').getText()
// ^ here was a mistake
.then(result => result, err => {
// ^ this error handling wasn't work
throw new Error(`Cannot get text of element: #someName\n${err}`);
})
.then(text => expect(text).toBe('correct'))
.then(done)
});
appium 服务器日志告诉我:
[HTTP] --> POST /wd/hub/session/63aa60d2-9638-4b1a-a226-cfbb2fcfce2c/element {"using":"css selector","value":"someName"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["css selector","someName","63aa60d2-9638-4b1a-a226-cfbb2fcfce2c"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[HTTP] <-- POST /wd/hub/session/63aa60d2-9638-4b1a-a226-cfbb2fcfce2c/element 500 4 ms - 152
[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"platformName":"android","app":"./app-dev-debug.apk","appPackage":"com.#####.dev.debug","appActivity":"com.#####.feature.start.StartActivity","avdReadyTimeout":1000,"udid":"LGK350RGNBS4TS","deviceName":"LG-K350","clearSystemFiles":true,"fullReset":true,"newCommandTimeout":120,"requestOrigins":{"url":"http://webdriver.io","version":"4.12.0","name":"webdriverio"}}}
但是jsmine卡住了没有抛出错误,记录:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
“完成”不是承诺
配置的茉莉花超时= 300000
主要问题:为什么 Jasmine 没有收到抛出的异常?
解决方案
找到解决方案(虚拟修复):
使用功能:
testMobile = <T>(promise: Client<T>, done: () => void): Client<void> =>
promise.then(done, err => {
expect(err).toBe('Ok');
done();
});
并使用:
it('wtf', done =>
testMobile(client.init()
.element('someName').getText()
.then(result => result, err => {
throw new Error(`Cannot get text of element: #someName\n${err}`);
})
.then(text => expect(text).toBe('correct')),
done)
};
推荐阅读
- javascript - 基于文档查询选择器定义 VAR 不起作用
- javascript - Promise 既解决又拒绝
- r - 同时修剪多个变量的因子标签
- r - 如何在 sendmailR 电子邮件中嵌入图像内联(不是附件)?
- html - 为什么 min-height:100vh 在容器上不起作用?
- excel - 循环遍历范围并清除正在评估的单元格下方 8 个单元格的内容
- python - Django Rest Framework:我应该使用 URL Slugs 还是查询参数来列出特定类别的项目?
- asp.net-mvc - CS1061: 'IEnumerable
' 不包含 'labViewResult' 的定义,也没有扩展方法 'labViewResult' - javascript - 分叉的 npm 包上没有发生安装后构建步骤
- pointers - 在 GO 中从 CGO 转换字符串数组