在 cypress.json 中动态设置 baseUrl
Dynamically set baseUrl in cypress.json
我有一个 laravel 应用程序并引入了 Cypress 测试。在我的 cypress.json
文件中,我将 baseUrl
值设置为字符串 localhost:8000
。问题是 cypress 测试 baseUrl 会根据我所在的环境(本地、生产等...)而改变,所以有没有办法在 cypress.json
文件中动态设置这个 baseUrl
?我询问 Laravel .env
因为 baseUrl 或 APP_URL
已经设置在那里。
谢谢。
当前cypress.json
"baseUrl": "http://127.0.0.1:8000", //How to make this dynamic based on app environment?
"chromeWebSecurity": false
您可以像这样从 cli 更改 baseURL 的值:
npx cypress run --config baseUrl=https://example.com/
或者,更好的方法是在 package.json
的脚本标签下创建多个命令,如下所示:
"scripts": {
"test": "cypress run",
"test:staging": "cypress run --config baseUrl=https://staging-example.com/",
"test:prod": "cypress run --config baseUrl=https://prod-example.com/"
}
然后就可以直接运行:
npm run test:staging
npm run test:prod
我有一个 laravel 应用程序并引入了 Cypress 测试。在我的 cypress.json
文件中,我将 baseUrl
值设置为字符串 localhost:8000
。问题是 cypress 测试 baseUrl 会根据我所在的环境(本地、生产等...)而改变,所以有没有办法在 cypress.json
文件中动态设置这个 baseUrl
?我询问 Laravel .env
因为 baseUrl 或 APP_URL
已经设置在那里。
谢谢。
当前cypress.json
"baseUrl": "http://127.0.0.1:8000", //How to make this dynamic based on app environment?
"chromeWebSecurity": false
您可以像这样从 cli 更改 baseURL 的值:
npx cypress run --config baseUrl=https://example.com/
或者,更好的方法是在 package.json
的脚本标签下创建多个命令,如下所示:
"scripts": {
"test": "cypress run",
"test:staging": "cypress run --config baseUrl=https://staging-example.com/",
"test:prod": "cypress run --config baseUrl=https://prod-example.com/"
}
然后就可以直接运行:
npm run test:staging
npm run test:prod