e2e-testing - 赛普拉斯管道 console.log 和命令日志输出
问题描述
是否可以重定向或捕获赛普拉斯浏览器日志和命令日志以输出?
我阅读了有关此主题的一些赛普拉斯 github问题。但我不知道如何使它工作。
基本上,我想在无头非 GUI 模式下捕获所有赛普拉斯 GUI 命令日志。如果我可以包含浏览器控制台日志会更好。目的是了解测试失败时发生了什么。
我使用teamcity作为ci。这是我的构建日志的示例。我也想在这里查看所有命令日志。实际上,任何在服务器端运行的 console.logcy.task
都会显示在构建日志中。跑步cy.task('log',message)
太手动了。有什么更聪明的方法吗?
[09:49:08][Step 1/1] 2 of 4: new actions (52s)
[09:50:00][Step 1/1] 3 of 4: new actions (52s)
[09:50:53][Step 1/1] 4 of 4: new actions (53s)
[09:51:47][Step 1/1] (Results)
[09:51:47][Step 1/1]
[09:51:47][Step 1/1] ┌─────────────────────────────────────┐
[09:51:47][Step 1/1] │ Tests: 8 │
[09:51:47][Step 1/1] │ Passing: 8 │
[09:51:47][Step 1/1] │ Failing: 0 │
[09:51:47][Step 1/1] │ Pending: 0 │
[09:51:47][Step 1/1] │ Skipped: 0 │
[09:51:47][Step 1/1] │ Screenshots: 0 │
[09:51:47][Step 1/1] │ Video: true │
[09:51:47][Step 1/1] │ Duration: 3 minutes, 38 seconds │
[09:51:47][Step 1/1] │ Estimated: 1 minute, 8 seconds │
[09:51:47][Step 1/1] │ Spec Ran: action/action_spec.js │
[09:51:47][Step 1/1] └─────────────────────────────────────┘
解决方案
从 Cypress 3.0.0 开始,您可以使用cy.task()
直接访问节点并输出到节点控制台。从文档:
// in test
cy.task('log', 'This will be output to the terminal')
// in plugins file
on('task', {
log (message) {
console.log(message)
return null
}
})
请参阅此处了解更多信息。
我不知道将赛普拉斯日志直接镜像到控制台的方法,但这至少是一种可行的选择。
推荐阅读
- azure-iot-hub - 使用事件网格的 IoT 中心事件延迟
- office-js - Outlook 客户端加载项:链接和 JS 重定向到其他域,打开新的浏览器选项卡
- mysql - iReport中的员工考勤日历报表设计
- wordpress - 我可以使用固定布局创建自定义 Woocommerce 结帐吗
- javascript - React axios 对 Django 后端的请求为空
- python - 如何在手写文本识别中对数字和单词进行分类
- typescript - 使用远程 couchdb 删除,未触发相应的 pouchDB 更改事件
- python - Python 中特定于操作系统的命名空间规则
- node.js - 在 lambda nodejs 中创建密码 pdf 文件
- android - 在android中获取时间戳的最佳方法?