首页 文章

赛普拉斯管道console.log和命令日志输出

提问于
浏览
2

是否可以将赛普拉斯浏览器日志和命令日志重定向或捕获到输出?

我在这个主题上读了一些赛普拉斯github issues . 但我不知道如何使它发挥作用 .

基本上,我想在无头非GUI模式下捕获所有赛普拉斯GUI命令日志 . 如果我可以包含浏览器控制台日志会更好 . 目的是了解测试失败时发生的情况 .

我使用teamcity作为ci . 这是我的构建日志的示例 . 我想在这里看到所有命令日志 . 实际上,使用 cy.task 在服务器端运行的任何console.log都会显示在构建日志中 . 运行 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]   └─────────────────────────────────────┘

1 回答

  • 3

    从赛普拉斯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
      }
    })
    

    有关详细信息,请参阅here .

    我不知道如何直接将赛普拉斯日志镜像到控制台,但这至少是一种可行的替代方案 .

相关问题