赛普拉斯管道console.log和命令日志输出 [英] Cypress pipe console.log and command log to output

查看:164
本文介绍了赛普拉斯管道console.log和命令日志输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to redirect or capture Cypress browser log and command log to output?

我读了一些赛普拉斯的github 问题关于此主题。但是我不知道如何使它工作。

I read some Cypress github issues on this topic. But I don't know how to make it work.

基本上,我想以无头非GUI模式捕获所有Cypress GUI命令日志。如果我可以包括浏览器控制台日志,那就更好了。目的是了解测试失败时发生的情况。

Basically, I want to capture all the Cypress GUI command logs in the headless non-GUI mode. If I can include browser console log will be even better. The purpose is to understand what happened when a test fails.

我使用teamcity作为ci。这是我的构建日志的示例。我也想在这里查看所有命令日志。实际上,使用 cy.task 在服务器端运行的任何console.log都会显示在构建日志中。运行 cy.task('log',message)太手工了。还有什么更聪明的方法吗?

I use teamcity as ci. Here is an example of my build log. I want to see all the command log here too. Actually, any console.log run on the server side using cy.task is displayed in the build log. Running cy.task('log',message) is too manual. Any smarter ways?

[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]   └─────────────────────────────────────┘


推荐答案

As在Cypress 3.0.0中,您可以使用 cy.task()直接访问节点并输出到节点控制台。来自文档:

As of Cypress 3.0.0, you can use cy.task() to access node directly and output to the node console. From the docs:

// in test
cy.task('log', 'This will be output to the terminal')



// in plugins file
on('task', {
  log (message) {
    console.log(message)
    return null
  }
})

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

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

I don't know of a way to mirror the Cypress logs to the console directly, but this is at least a workable alternative.

这篇关于赛普拉斯管道console.log和命令日志输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆