我有一个 Laravel 应用程序并引入了 Cypress 测试。在我的cypress.json文件中,我将baseUrl值设置为localhost:8000. 问题是 cypress 测试 baseUrl 将根据我所在的环境(本地、生产等)而改变,所以有没有办法baseUrl在文件中动态设置它cypress.json?我询问 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
Run Code Online (Sandbox Code Playgroud)
Ala*_*Das 15
您可以从 cli 更改 baseURL 的值,如下所示:
npx cypress run --config baseUrl=https://example.com/
Run Code Online (Sandbox Code Playgroud)
或者,更好的方法是在脚本标签下创建多个命令,如下所示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/"
}
Run Code Online (Sandbox Code Playgroud)
然后就可以直接运行:
npm run test:staging
npm run test:prod
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5898 次 |
| 最近记录: |