首页 > 解决方案 > 赛普拉斯管道 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]   └─────────────────────────────────────┘

标签: e2e-testingcypress

解决方案


从 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
  }
})

请参阅此处了解更多信息。

我不知道将赛普拉斯日志直接镜像到控制台的方法,但这至少是一种可行的选择。


推荐阅读