BrowserStack cypress Run > cypress-cucumber-preprocessor 依赖关系图 + cypress 文件夹出错

问题描述

使用 cypress 启动测试到浏览器堆栈时

目前,通过在我的开发环境 (ubuntu) 上运行命令进行调试

npm run browserstack

it calls the script from package.json "browserstack": "./node_modules/.bin/browserstack-cypress run --sync"

我的功能日志执行在浏览器构建仪表板中显示以下错误

Running:  features\desktop.feature                                              (NaN of undefined)

Oops...we found an error preparing this test file:

  cypress\integration\features\desktop.feature

The error was:

Error: Can't walk dependency graph: Cannot find module 'C:Usershellodocumentsdocumentscypress_testcypress_test_folder
ode_modulescypress-cucumber-preprocessorlib
esolveStepDeFinition' from 'cypress_test_folder\cypress\integration\features'
    required by cypress_test_folder\cypress\integration\features\desktop.feature
    at cypress_test_folder\node_modules\browser-resolve\node_modules\resolve\lib\async.js:46:17
    at process (cypress_test_folder\node_modules\browser-resolve\node_modules\resolve\lib\async.js:173:43)
    at ondir (cypress_test_folder\node_modules\browser-resolve\node_modules\resolve\lib\async.js:188:17)
    at load (cypress_test_folder\node_modules\browser-resolve\node_modules\resolve\lib\async.js:69:43)
    at onex (cypress_test_folder\node_modules\browser-resolve\node_modules\resolve\lib\async.js:92:31)
    at cypress_test_folder\node_modules\browser-resolve\node_modules\resolve\lib\async.js:22:47
    at callback (C:\Windows\cypress_package\6.8.0\node_modules\graceful-fs\polyfills.js:289:20)
    at FSReqCallback.oncomplete (fs.js:172:21)

This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

- A missing file or dependency
- A Syntax error in the file or one of its dependencies

Fix the error in your code and re-run your tests.

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        0                                                                                │
  │ Passing:      0                                                                                │
  │ Failing:      1                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     0 seconds                                                                        │
  │ Spec Ran:     features\desktop.feature                                                         │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Uploading Results)

  - nothing to Upload

我的 browserstack.json 如下

{
    "auth": {
        "username": "<username>","access_key": "<access_key>"
    },"browsers": [
        {
            "os": "Windows 10","browser": "chrome","versions": ["latest"]
        }
    ],"run_settings": {
        "cypress_version" : "6","cypress_config_file": "./cypress.json","project_name": "myproject","build_name": "ui-automation","specs": ["cypress/integration/features/desktop.feature","cypress/integration/features/desktop/desktop.js"],"exclude": [],"parallels": "Here goes the number of parallels you want to run","npm_dependencies": {
            "cypress-cucumber-preprocessor": "^1.19.2","browserstack-cypress-cli": "^1.8.1","cypress": "^3.8.3","cypress-xpath": "^1.6.2"          
        },"package_config_options": {
            "cypress_options": {
                "testFiles": "**/*.feature","ignoreTestFiles": "*.js","chromeWebSecurity": false
            },"cypress-cucumber-preprocessor_options": {
                "nonGlobalStepDeFinitions": true,"step_deFinitions": "cypress/integration/features/dekstop/"
            }            
        },"headless": false
    },"connection_settings": {
        "local": false,"local_identifier": null,"local_mode": null,"local_config_file": null
    },"disable_usage_reporting": false
}

按照开始指南和任何其他提示,我没有发现发生了什么,尤其是在浏览器堆栈日志中,它试图找到一个带有 Windows 路径的模块,而我所有的测试环境都在 linux ubuntu 上 > 我的目标接下来在 gitlab 上运行所有这些

解决方法

能否在broserstack.json https://www.browserstack.com/docs/automate/cypress/npm-packages 你可以参考这里的黄瓜丝柏样品:https://github.com/ashwingonsalves/cypress-browserstack-cucumber