如何將 Bitbucket 存盤庫變數傳遞到我npm run在管道中運行的 Cypress.io 測驗腳本中?
管道和測驗作業,但我無法將 Bitbucket 變數放入測驗檔案本身。我可以bitbucket-pipeline.yml按照 Bitbucket 在存盤庫變數頁面上提供的說明訪問存盤庫變數,但我無法訪問cypress/integration/example.js. 我想存盤測驗腳本用作 Bitbucket 存盤庫變數的憑據。
這是我的代碼...
bitbucket-pipeline.yml
image: cypress/included:3.2.0
pipelines:
custom:
robot:
- step:
script:
- printenv
- npm ci
- npm run e2e
- 使用賽普拉斯提供的影像
- 我可以通過查看我的存盤庫變數
printenv
包.json
{
...
"scripts": {
"e2e": "cypress run"
},
...
"dependencies": {
"cypress": "^9.4.1"
}
}
賽普拉斯/集成/example.js
describe('A', () => {
it('should B', () => {
cy.visit('https://google.com');
});
});
- 我想在
it('should B' ...)方法內部使用 Bitbucket 存盤庫變數。
在此先感謝您的幫助。
uj5u.com熱心網友回復:
我找到了關于環境變數的 Cypress.io 檔案: https ://docs.cypress.io/guides/guides/environment-variables
bitbucket-pipeline.yml
image: cypress/included:3.2.0
pipelines:
custom:
robot:
- step:
script:
- npm ci
- export CYPRESS_example=$example
- export CYPRESS_whatever=$whatever
- npm run e2e
其中example是 Bitbucket 存盤庫變數的名稱。可能區分大小寫。
添加$以參考bitbucket-pipeline.yml檔案中的 Bitbucket 存盤庫變數。
使用CYPRESS_將其標識為賽普拉斯環境變數。 https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS _
然后你可以通過在測驗規范中使用它Cypress.env("example")
我實際上不得不進行型別轉換,因為 Bitbucket 提供了意想不到的資料型別......
cy.get('[name="password"]').clear().type(Cypress.env("example").toString());
uj5u.com熱心網友回復:
您可以使用該插件為每個部署設定一個組態檔,并且在運行腳本時,您可以設定運行腳本的環境,例如,如果插件在管道內正確設定,則下面的示例將起作用。
npx cypress 運行 --env version="qa" npx cypress 運行 --env version="prod"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/443040.html
上一篇:在DaemonSet中添加欄位會回傳“io.k8s.api.apps.v1.DaemonSet中的未知欄位“nodeAffinity””
下一篇:npminstall沒有更新依賴
