这是我测试运行时在 cypress 中遇到的错误

问题描述 投票:0回答:1

我目前在设置用于注册和登录测试的测试环境时面临一些挑战。我尝试按照通常的步骤和文档进行操作,但我不断遇到环境进程未定义的情况。我希望这里有人可以就如何排查和解决此问题提供一些指导或建议。

参考错误 以下错误源自您的测试代码,而不是来自 Cypress。

流程未定义

当赛普拉斯检测到源自您的测试代码的未捕获错误时,它将自动使当前测试失败。

赛普拉斯无法将此错误与任何特定测试相关联。

我们动态生成了一个新的测试来显示此故障。 node_modules/ci-info/index.js:5:1 3 | const 供应商 = require('./vendors.json') 4 |

5 | const env = 进程.env | ^

这是堆栈跟踪 在 ./node_modules/ci-info/index.js (webpack://imatch/./node_modules/ci-info/index.js:5) 在 webpack_require (webpack://imatch/webpack/bootstrap:19) 在 ./node_modules/is-ci/index.js (webpack://imatch/./node_modules/is-ci/index.js:3) 在 webpack_require (webpack://imatch/webpack/bootstrap:19) 在 ./node_modules/cypress/lib/util.js (webpack://imatch/./node_modules/cypress/lib/util.js:12:13) 在 webpack_require (webpack://imatch/webpack/bootstrap:19) 在 ./node_modules/cypress/index.js (webpack://imatch/./node_modules/cypress/index.js:6:13) 在 webpack_require (webpack://imatch/webpack/bootstrap:19) 在 ./cypress/support/commands.js (webpack://imatch/./cypress/support/commands.js:32:16) 在 webpack_require (webpack://imatch/webpack/bootstrap:19) 从之前的活动来看: 在 Promise.longStackTracesCaptureStackTrace [as _captureStackTrace] (http://localhost:55853/__cypress/runner/cypress_runner.js:3486:19) 在 Promise._then (http://localhost:55853/__cypress/runner/cypress_runner.js:1239:17) 在 Promise.then (http://localhost:55853/__cypress/runner/cypress_runner.js:1132:17) 在 runScriptsFromUrls (http://localhost:55853/__cypress/runner/cypress_runner.js:110842:136) 在 Object.runScripts (http://localhost:55853/__cypress/runner/cypress_runner.js:110883:12) 在 $Cypress.onSpecWindow (http://localhost:55853/__cypress/runner/cypress_runner.js:40889:67)

javascript cypress
1个回答
0
投票

您的错误表明

process
未定义。

您应该导入它。

const process = require('node:process');

const env = proccess.env;

另一种方法是直接导入

env

process.env 属性返回一个包含用户环境的对象。

您可以访问环境变量,例如

env.myVariable
,并为环境变量分配/重新分配值。

const { env } = require('node:process');

console.log(env.foo) // 'foo'
env.foo = 'bar';
console.log(env.foo) // 'bar'

更多信息

© www.soinside.com 2019 - 2024. All rights reserved.