我正在为我的存储库编写工作流,每当有代码推送时,我都想运行测试用例。
以下是来自.yml文件的代码片段:
- name: Run cypress test
with:
env: true
env:
username: ${{secrets.CYPRESS_USERNAME}}
password: ${{secrets.CYPRESS_PASSWORD}}
run: npm run cy:test --env fileConfig=production, username=$username, password=$password
continue-on-error: false
JSON:中的代码段
{
"env": {
"userId": "1",
"environment": "production",
"baseUrl": " base URL"
}
}
因此,我想在Cyprus run命令中传递用户名和密码以及配置文件,以便将它们设置为env变量,因为我在登录测试模块中使用用户名和密码。
用上面的代码我得到错误:
工作流无效。github/workflows/main.yml(行:43,列:9(:意外值"run"。github/wworkflows/main.yml(列:36(:缺少必需属性:使用
谢谢:(
首先,您需要将env变量作为空字符串添加到cypry.json:上
{
"env": {
"userId": "1",
"environment": "production",
"baseUrl": "base URL",
"username": "",
"password": ""
}
}
在main.yml文件中,您需要将CYPRESS_前缀添加到变量中:
env:
CYPRESS_username: ${{secrets.CYPRESS_USERNAME}}
CYPRESS_password: ${{secrets.CYPRESS_PASSWORD}}
此外,您应该使用可以在柏树文档中找到的设置(https://docs.cypress.io/guides/continuous-integration/github-actions#Basic-Setup(,例如:
name: Cypress Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v2
with:
build: npm run build
start: npm start
env:
CYPRESS_username: ${{secrets.CYPRESS_USERNAME}}
CYPRESS_password: ${{secrets.CYPRESS_PASSWORD}}
您还应该阅读这篇文章:https://glebbahmutov.com/blog/keep-passwords-secret-in-e2e-tests/