【问题标题】:Playwright: How to pass environment variables from library to pipeline?剧作家:如何将环境变量从库传递到管道?
【发布时间】:2023-02-18 07:34:03
【问题描述】:

背景

我有一个在 Azure DevOps 管道中运行 Playwright 集成测试的 React/TypeScript 项目。管道从 Azure DevOps 库获取环境变量。


问题

我可以在本地针对部署的预生产环境成功运行测试。

但是,测试在管道中失败了。它们失败是因为管道无法读取我试图从库中传入的环境变量。

失败的代码行:

await page.getByRole('textbox', { name: 'myVariable' }).fill(process.env.MyVariable as string);

我的环境变量上的管道错误:


如何将环境变量从库传递到管道,以便 Playwright 可以读取它们?

【问题讨论】:

    标签: reactjs typescript azure integration-testing playwright


    【解决方案1】:

    解决方案

    1. 我将测试文件名从 myFile.spec.ts 更新为 myFile.spec.tsx
    2. 我在我的环境变量前添加了REACT_APP_前缀。
      await page.getByRole('textbox', { name: 'myVariable' }).fill(process.env.REACT_APP_MY_VARIABLE as string);
      
      1. 现在我的 Azure DevOps 管道可以读取 Azure DevOps 库中的变量,测试成功!

    【讨论】:

      猜你喜欢
      • 2020-12-05
      • 2019-09-13
      • 1970-01-01
      • 2020-03-27
      • 2022-07-29
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 2018-09-21
      相关资源
      最近更新 更多