提问人:user22068518 提问时间:11/14/2023 最后编辑:jonrsharpeuser22068518 更新时间:11/14/2023 访问量:45
GitHub Actions 似乎无法识别我的 .env 机密
GitHub Actions doesn't seem to recognize my .env secrets
问:
我有一个 Playwright 项目,我正在尝试使用文件和 GitHub 机密进行身份验证。.env
我:.env
USERNAME={redacted}
PASSWORD={redacted}
在测试本身(在本地通过)中,我使用了 TypeScript 的语法:process.env.{variable}!
test.describe.serial('Dashboard', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.getByPlaceholder('Email').fill(process.env.USERNAME!);
await page.getByPlaceholder('Password').fill(process.env.PASSWORD!);
在 GitHub 中,我设置了与存储库机密相同的变量。这是我的文件:playwright.yml
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
env:
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
当测试在 GH 中运行时,似乎正在正确访问机密,但是当测试到达第一个断言时,测试将不可避免地失败:
Run npx playwright test
npx playwright test
shell: /usr/bin/bash -e {0}
env:
USERNAME: ***
PASSWORD: ***
...
**.spec.ts:16:7 › *** › create a new *** ────
Test timeout of 30000ms exceeded while running "beforeEach" hook.
3 |
4 | test.describe.serial('Stress testing UI', () => {
> 5 | test.beforeEach(async ({ page }) => {
| ^
6 | await page.goto('/');
7 | await page.getByPlaceholder('Email').fill(process.env.USERNAME!);
8 | await page.getByPlaceholder('Password').fill(process.env.PASSWORD!);
at /home/runner/work/{redacted}/{redacted}/tests/***.spec.ts:5:8
Error: locator.click: Page closed
=========================== logs ===========================
waiting for getByRole('link', { name: '{redacted}' })
============================================================
8 | await page.getByPlaceholder('Password').fill(process.env.PASSWORD!);
9 | await page.getByRole('button', { name: 'Sign in' }).click();
> 10 | await page.getByRole('link', { name: '{redacted}' }).click();
我做错了什么?
我做了什么,我的期望是什么: 我编写的 Playwright 测试在本地通过,但在 GH 中运行时失败。GH 机密似乎正在以 UNDEFINED 或类似方式传递。
我希望我的应用程序在云中成功进行身份验证,就像在本地进行身份验证一样。
答: 暂无答案
评论
.env
/sign_in
await page.getByRole('link', { name: '{redacted}' }).click();