首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cypress +mochawesome未定义为consol的报告

Cypress +mochawesome未定义为consol的报告
EN

Stack Exchange QA用户
提问于 2020-01-28 19:23:09
回答 1查看 216关注 0票数 2

我有一个简单的测试来测试令人毛骨悚然的--当我在终端上运行它时,我会在测试中多次“未定义”。怎么移除它?

代码语言:javascript
复制
undefined

  Sample test
    √ Passed
    1) Failing
undefined
undefined
  1 passing (4s)
  1 failing
undefined
  1) Sample test
       Failing:

我的测试:

代码语言:javascript
复制
context('Sample test', () => {
    it('Passed', () => {
        cy.document().title().should('not.contain', 'unicorns')
    })
    it('Failing', () => {
        cy.document().title().should('contain', 'unicorns')
    })
  })

代码语言:javascript
复制
context('Second sample test', () => {
    it('A passing test', () => {
        cy.document().title().should('not.contain', 'unicorns')
    })
  })
EN

回答 1

Stack Exchange QA用户

发布于 2020-01-29 13:56:36

我试图在你的例子和我自己的测试中找出“未定义”的来源。

在玩了一段时间之后,“未定义”似乎来自Cypress,而不是Mocha记者,因为我尝试过在没有它的情况下运行测试,而且“未定义”仍然在控制台中。

所以,我的配置只是某物。像这样:

代码语言:javascript
复制
{
    "projectId": "<my_project_id>",
    "baseUrl": "<url>", 
    "integrationFolder": "cypress/integration/",
    "testFiles": "test*.js"
}

我使用这样的命令运行测试:.\node_modules\.bin\cypress run --config-file test.json

这些测试非常简单,如:

代码语言:javascript
复制
describe('Sample test', function() {
    it('Passed', function() {
        cy.visit('/');      
    });
});

控制台中的输出如下:

代码语言:javascript
复制
====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.8.3                                                                              │
  │ Browser:    Electron 78 (headless)                                                             │
  │ Specs:      1 found (accessSitesForRegisteredUserOnly.js)                                      │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  accessSitesForRegisteredUserOnly.js                                             (1 of 1)
undefined
...
...
(and more undefined later on)

如果我在Cypress Test中运行相同的测试,那么测试就没有问题,任何地方都没有“未定义的”。

我在Windows 10上用Cypress 3.8.3尝试了所有这些。

您还可以查看古柏杂志上的一些公开问题,如果您在那里找不到答案,您可能会选择填写一个新的问题,这可能是一个bug。

编辑:

更多的信息。这个问题将是特定于平台的,很可能与Windows控制台和一些颜色有关。如果我在Linux系统上运行相同的示例,控制台中就没有“未定义”:

代码语言:javascript
复制
$ ./node_modules/.bin/cypress run --config-file test.json
====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.8.2                                                                              │
  │ Browser:    Electron 78 (headless)                                                             │
  │ Specs:      1 found (test.js)                                                                  │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  test.js                                                                         (1 of 1)


  Sample test
    ✓ Passed (7690ms)


  1 passing (8s)


  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        true                                                                             │
  │ Duration:     7 seconds                                                                        │
  │ Spec Ran:     test.js                                                                          │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Video)

  -  Started processing:  Compressing to 32 CRF                                                     
  -  Finished processing: /home/pavel/testing/alpine/AlpinePro.Tests.Cypress/cypress/     (1 second)
                          videos/test.js.mp4                                                        


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  test.js                                  00:07        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        00:07        1        1        -        -        -  

即使用摩卡也做了测试:

代码语言:javascript
复制
{
    "projectId": "",
    "baseUrl": "<url>",
    "screenshotsFolder": "cypress/results/screenshots",
    "videosFolder": "cypress/results/videos",
    "viewportHeight": 1080,
    "viewportWidth": 1920,
    "video": true,
    "fixturesFolder": "cypress/fixtures_dev",
    "reporter": "cypress-multi-reporters",
    "reporterOptions": {
        "configFile": "reporterOptions.json"
    },
    "integrationFolder": "cypress/integration",
    "testFiles": "test*.js"
}

(非常主观的)方法是明确的:使用适当的操作系统:)

票数 1
EN
页面原文内容由Stack Exchange QA提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://sqa.stackexchange.com/questions/42342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档