有1测试,2测试,3测试等。cypress.config.js:
const { defineConfig } = require('cypress')
module.exports = defineConfig({
video: true,
viewportWidth: 1920,
viewportHeight: 1024,
numTestsKeptInMemory: 1,
defaultCommandTimeout: 10000,
e2e: {
// specPattern: 'cypress/integration/2test.cy.js, cypress/integration/1test.cy.js',
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'https://localhost:3000',
},
})另外,我添加了specPattern,但这不是工作
cypress.json:
{
"baseUrl": "https://localhost:3000",
"video": true,
"viewportWidth": 1920,
"viewportHeight": 1024,
"numTestsKeptInMemory": 1,
"defaultCommandTimeout": 10000,
"testFiles": [
"2test.js",
"1test.js"
]}我把柏树更新到10.3.0版本。我想要启动命令:node_modules/..bin/cypress run,但是所有测试都开始运行。早期,使用以前的版本,我启动命令(node_node/..bin/cypress run)并测试运行prom testList cypress.json。我怎样才能在cepress 10.3.0上做到这一点呢?
..gitlab ci.yml:
image: node:12.13.1
stages:
- eslint
- build
- deploy
eslint:
tags:
- docker
stage: eslint
script:
- npm i
- npx eslint -f table ./src || true
- export ERRORS_COUNT=$(npx eslint -f ./formatter.js ./src)
- echo "Total number of errors - $SUM_OF_ERRORS"
- echo "Number of errors in current commit - $ERRORS_COUNT"
- if [ "$ERRORS_COUNT" -gt "$SUM_OF_ERRORS" ]; then exit 1; else exit 0; fi
build:
tags:
- docker
stage: build
script:
- npm i
- echo "export const VERSION = "$CI_PIPELINE_ID";" > /builds/synergy/dps1/src/version.js
- CI=false npm run build-qa
#- CI=false npm run build-beta
#- CI=false npm run build
artifacts:
paths:
- build/
only:
- develop
deploy:
tags:
- docker
only:
- develop
stage: deploy
script:
- 'which ssh-agent || ( apk update && apk add openssh )'
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- curl https://ipinfo.io/ip
- echo -e "$PRIVATE_KEY" > /root/.ssh/id_rsa
- chmod 600 /root/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- echo "deploying to "${DEPLOY_SERVERS}""
- ls
- pwd
- scp -r /builds/synergy/dps1/build ec2-user@"${DEPLOY_SERVERS}":/usr2/dpsone/
- ssh ec2-user@"${DEPLOY_SERVERS}" 'bash' < ./updateAndRestart.shpackage.json:
{
"name": "dps-one-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@ant-design/icons": "^4.1.0",
"ant-design-pro": "^2.3.2",
"antd": "3.19.6",
"axios": "^0.21.1",
"chart.js": "^3.8.0",
"classnames": "2.2.6",
"cypress-react-selector": "^2.3.12",
"d3": "^3.5.16",
"d3-geo": "^2.0.1",
"d3-tip": "^0.6.7",
"downloadjs": "^1.4.7",
"express": "^4.17.1",
"html2canvas": "^1.0.0-rc.7",
"interactjs": "^1.9.4",
"lodash": "^4.17.15",
"moment": "2.24.0",
"moment-timezone": "^0.5.28",
"path": "^0.12.7",
"prop-types": "15.7.2",
"rc-tween-one": "^2.5.0",
"react": "16.8.6",
"react-calendar-timeline": "^0.26.7",
"react-chartjs-2": "^4.1.0",
"react-charts": "^2.0.0-beta.7",
"react-color": "^2.19.3",
"react-device-detect": "^1.12.1",
"react-dom": "16.8.6",
"react-google-login": "^5.1.10",
"react-image-lightbox": "^5.1.0",
"react-lazylog": "^4.5.2",
"react-redux": "7.1.0",
"react-router-dom": "5.0.1",
"react-scripts": "^3.3.0",
"react-simple-maps": "2.1.2",
"react-tooltip": "latest",
"react-virtualized": "^9.21.2",
"redux": "4.0.1",
"redux-thunk": "2.3.0"
},
"scripts": {
"start": "HTTPS=true react-scripts start",
"build": "react-scripts build",
"build-beta": "REACT_APP_SECRET_CODE=beta react-scripts build",
"build-qa": "REACT_APP_SECRET_CODE=qa react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"tests:in:order": "cypress run --spec \"cypress/e2e/tests-in-order.cy.js\""
},
"lint-staged": {
"*.{js,jsx}": [
"prettier --write",
"git add"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@cypress/react": "^5.9.4",
"@cypress/webpack-dev-server": "^1.4.0",
"babel-eslint": "10.0.3",
"cypress": "^10.3.0",
"cypress-file-upload": "^5.0.8",
"eslint": "6.6.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "5.0.0",
"eslint-plugin-import": "2.17.3",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-prettier": "3.1.0",
"eslint-plugin-react": "7.13.0",
"husky": "2.4.1",
"lint-staged": "8.2.1",
"prettier": "1.18.2",
"sass": "^1.47.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && ./node_modules/.bin/cypress run --headless"
}
}
}发布于 2022-07-14 12:10:10
在您的cypress/e2e文件夹中,创建一个名为tests-in-order.cy.js的文件,并在其中按您希望它们执行的顺序导入测试,如下所示:
import './1test.cy.js'
import './2test.cy.js'
import './3test.cy.js'然后执行测试:
在测试运行程序中,您可以单击tests-in-order.cy.js文件,所有测试都将按预期顺序执行。
在CLI中,使用如下命令。
npx cypress run --spec "cypress/e2e/tests-in-order.cy.js"但是有一点要补充的是,如果您在CLI中运行测试,最终报告将只包含tests-in-order.cy.js和所有文件中的测试用例计数,如下所示:

转到package.json并在脚本下创建如下命令:
"scripts": {
"tests:in:order": "cypress run --spec \"cypress/e2e/tests-in-order.cy.js\"",
}然后从下一次开始只需执行命令npm run tests:in:order
发布于 2022-07-15 07:39:52
"husky": {
"hooks": {
"pre-commit": "lint-staged && ./node_modules/.bin/cypress run --spec \"cypress/e2e/tests-in-order.cy.js\""
}
}https://stackoverflow.com/questions/72980106
复制相似问题