通过docker命令运行cypress时,cypress type()变得不确定 [英] While running cypress via docker command, cypress type() getting undefined
问题描述
在Windows 10命令提示符下使用以下docker命令运行cypress测试时,发生以下错误。
docker run -it -v%cd%:/ e2e -w / e2e cypress / included:3.4.0
但是在通过 npm运行cypress测试时,从Windows命令中运行cy:test-uattest
脚本,提示所有测试成功运行。知道为什么运行docker命令时 cy.type()
命令会变为'undefined'。
cy.get('input [name = firstInput]')。type(Cypress.env('firstNumber'));
下面是我的Cypress.env.json文件
{
numTestsKeptInMemory:3,
firstNumber: 1000
}
运行docker命令时出错:
CypressError:cy.type()仅接受字符串或数字。您传入了:Object.cypressErr(https://someurl.net/__cypress/runner/cypress_runner.js:84963:11)中的'undefined'
在Object.throwErr(https:// someurl .net / __ cypress / runner / cypress_runner.js:84916:18)
at Object.throwErrByPath(https://someurl.net/__cypress/runner/cypress_runner.js:84947:17)
at Context .type(https://someurl.net/__cypress/runner/cypress_runner.js:71800:16)
(位于Context)。< anonymous> (https://someurl.net/__cypress/runner/cypress_runner.js:80518:21)
at https://someurl.net/__cypress/runner/cypress_runner.js:80223:33
at tryCatcher(https://someurl.net/__cypress/runner/cypress_runner.js:134216:23)
在Promise._settlePromiseFromHandler(https://someurl.net/__cypress/runner/cypress_runner.js:132234:31 )
在Promise._settlePromise(https://someurl.net/__cypress/runner/cypress_runner.js:132291:18)
在Promise._settlePromiseCtx(https://someurl.net/__cypress/runner /cypress_runner.js:132328:10)
在Async._drainQueue(https://someurl.net/__cypress/runner/cypress_runner.js:129145:12)
在Async._drainQueues(https:/ /someurl.net/__cypress/runner/cypress_runner.js:129150:10)
在< anonymous>
根据评论,这需要更多的调查。 / p>
同时,您可以使用环境变量:
创建文件 .env
(名称不重要,只要您在下一步中使用该名称)就具有以下内容:
CYPRESS_numTestsKeptInMemory = 3
CYPRESS_firstNumber = 1000
在docker中使用以下命令运行测试:
docker run -it -v%cd%:/ e2e -w / e2e --env-file .env cypress / included :3.4.0
While running the cypress test using below docker command from windows 10 command prompt, the below error occurs.
docker run -it -v %cd%:/e2e -w /e2e cypress/included:3.4.0
But while running the cypress test by npm run cy:test-uattest
script from windows command prompt all the test run successfully. Any idea why the cy.type()
command becomes 'undefined' while running the docker command.
cy.get('input[name="firstInput"]').type(Cypress.env('firstNumber'));
Below is my Cypress.env.json file
{
"numTestsKeptInMemory": 3,
"firstNumber":"1000"
}
Error while running the docker command:
CypressError: cy.type() can only accept a String or Number. You passed in: 'undefined'
at Object.cypressErr (https://someurl.net/__cypress/runner/cypress_runner.js:84963:11)
at Object.throwErr (https://someurl.net/__cypress/runner/cypress_runner.js:84916:18)
at Object.throwErrByPath (https://someurl.net/__cypress/runner/cypress_runner.js:84947:17)
at Context.type (https://someurl.net/__cypress/runner/cypress_runner.js:71800:16)
at Context.<anonymous> (https://someurl.net/__cypress/runner/cypress_runner.js:80518:21)
at https://someurl.net/__cypress/runner/cypress_runner.js:80223:33
at tryCatcher (https://someurl.net/__cypress/runner/cypress_runner.js:134216:23)
at Promise._settlePromiseFromHandler (https://someurl.net/__cypress/runner/cypress_runner.js:132234:31)
at Promise._settlePromise (https://someurl.net/__cypress/runner/cypress_runner.js:132291:18)
at Promise._settlePromiseCtx (https://someurl.net/__cypress/runner/cypress_runner.js:132328:10)
at Async._drainQueue (https://someurl.net/__cypress/runner/cypress_runner.js:129145:12)
at Async._drainQueues (https://someurl.net/__cypress/runner/cypress_runner.js:129150:10)
at <anonymous>
Based on the comments, this needs more investigation.
In the meantime, you can use environment variables:
Create a file .env
(name is not important, as long as you use the same in the next step) with the following contents:
CYPRESS_numTestsKeptInMemory=3
CYPRESS_firstNumber=1000
Run your tests in docker with:
docker run -it -v %cd%:/e2e -w /e2e --env-file .env cypress/included:3.4.0
这篇关于通过docker命令运行cypress时,cypress type()变得不确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!