While running cypress via docker command, cypress type() getting undefined

China☆狼群 提交于 2020-03-04 18:29:50

问题


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>

回答1:


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


来源:https://stackoverflow.com/questions/60463893/while-running-cypress-via-docker-command-cypress-type-getting-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!