【问题标题】:Where are fixtures located in the file structure of synpress (cypress) tests?synpress (cypress) 测试的文件结构中的固定装置在哪里?
【发布时间】:2022-07-19 01:39:54
【问题描述】:

我正在尝试使用 synpress 测试我的 react 应用程序,它是 cypress 的包装器,可让您与 metamask 加密钱包浏览器扩展进行交互。我已经设置了我的测试并且它们正在工作,但是我需要为其中一些使用一个固定装置,但我无法弄清楚固定装置的存储位置。

https://github.com/synthetixio/synpress#readme

以下是我当前的文件夹设置(与文档相同):

project_dir
└── src
└── tests
    └── e2e
        └── .eslintrc.js
        └── tsconfig.json
        └── specs
            └── example-spec.js
        └── pages
            └── example-page.js

我需要从夹具中读取一些数据,所以我在 e2e 目录中添加了一个夹具文件夹(例如它位于 project_dir/tests/e2e/fixtures),但无论我尝试什么,它都会出错并说夹具应该存储在node_modules@synthetixio/synpress/fixtures/ 下,我认为这是不正确的。

使用灯具是否需要额外的配置?

【问题讨论】:

    标签: testing cypress fixtures metamask e2e


    【解决方案1】:

    您可以在config.js文件中配置fixture文件夹路径

    {
     "fixturesFolder": "/tests/e2e/fixtures"
    }
    

    您还可以在 Cypress Test Runner 中验证夹具文件夹的值。

    1. 打开 Cypress 测试运行器:npx cypress open
    2. 设置
    3. 查找夹具文件夹

    【讨论】:

      【解决方案2】:

      看看例子package.jsonscriptshere,可以在命令行指定fixtures文件夹

      "test:e2e": "start-server-and-test ... --config='fixturesFolder=tests/e2e/fixtures'"
      

      或者尝试将synpress.json 添加到项目根目录 - synpress.json

      {
          "baseUrl": "http://localhost:3000",
          "userAgent": "synpress",
          "retries": { "runMode": 0, "openMode": 0 },
          "integrationFolder": "tests/e2e/specs",
      
          "fixturesFolder": "tests/e2e/fixtures",
      
          "screenshotsFolder": "tests/e2e/screenshots",
          "videosFolder": "tests/e2e/videos",
          "chromeWebSecurity": true,
          "viewportWidth": 1366,
          "viewportHeight": 768,
          "component": {
              "componentFolder": ".",
              "testFiles": "**/*spec.{js,jsx,ts,tsx}"
          },
          "env": {
              "coverage": false
          },
          "defaultCommandTimeout": 30000,
          "pageLoadTimeout": 30000,
          "requestTimeout": 30000
      }
      

      【讨论】:

        【解决方案3】:

        如果您尝试将图像加载到输入文件中,只需这样做,这为我节省了很多时间。

        cy.get('input[type="file"]', { force: true }).selectFile({ 内容:'文件路径', 文件名:'文件名', mimeType: '图像/jpeg', }, { 强制:真 });

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-08-30
          • 2022-08-02
          • 2016-06-03
          • 2015-08-08
          • 1970-01-01
          • 2010-11-28
          • 2012-11-18
          相关资源
          最近更新 更多