在cypress.json中动态设置baseUrl



我有一个laravel应用程序,并引入了Cypress测试。在我的cypress.json文件中,我将baseUrl值设置为localhost:8000的字符串。问题是Cyprus测试baseUrl将根据我所处的环境(本地、生产等(而更改,因此有没有办法在cypress.json文件中动态设置此baseUrl?我询问Laravel.env,因为baseUrl或APP_URL已经设置在那里。

谢谢。

当前塞浦路斯.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中的script标签下创建多个命令,如下所示:

"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

最新更新