在插件中使用假视频我无法在赛普拉斯的测试流程中使用两个视频

Noe*_*miG 5 browser plugins cypress

我在测试流程中有两个摄像头。视频必须通过不同的方式进行检查 在插件中使用假视频我可以伪造相机,但无法更改视频。

我必须在一个 spec.js 中检查具有不同视频的两个摄像头

你能帮我在一个spec.js中使用两个视频吗,两个视频都可以播放,我可以更改在哪个相机中播放哪个视频?

插件/index.js

module.exports = (on, config) => {

  on('before:browser:launch', (browser = {}, args) => {
    // args.push('--use-fake-device-for-media-stream')
    if (browser.name === 'chrome') {
      args.push('--use-fake-ui-for-media-stream')
      args.push('--use-fake-device-for-media-stream')
     args.push('--use-file-for-fake-video-capture=C:\\NOEMI\\EjemploWebcam\\webcam-tests\\cypress\\fixtures\\akiyo_cif.y4m')  
      //args.push('--use-file-for-fake-video-capture=C:\\NOEMI\\onboardingRepos\\onboarding-web\\cypress\\fixtures\\prueba.y4m')
    }

    return args



  })
}
Run Code Online (Sandbox Code Playgroud)

小智 2

我能够通过使用任务命令并替换通过的文件内容 在运行时更改视频源--use-file-for-fake-video-capture。其中棘手的部分是,如此处所述,需要getUserMedia()在替换文件后再次调用。

// cypress.config.js
  setupNodeEvents(on, config) {
    on("before:browser:launch", (browser, launchOptions) => {
      if (browser.family === "chromium" && browser.name !== "electron") {
        const videoPath = path.resolve(__dirname, "cypress", "fixtures", "webcam.y4m");

        launchOptions.args.push(`--use-file-for-fake-video-capture=${videoPath}`);
      }

      return launchOptions;
    });

    on("task", {
      changeVideoSource(videoSource) {
        console.log("TASK - Changing video source to", videoSource);

        const webcamPath = path.join("cypress", "fixtures", "webcam.y4m");
        const sourceVideoPath = path.join("cypress", "fixtures", videoSource);

        const video = fs.readFileSync(sourceVideoPath);

        fs.writeFileSync(webcamPath, video);

        return null;
      },
      resetVideoSource() {
        console.log("TASK - Resetting video source");
        const webcamPath = path.join("cypress", "fixtures", "webcam.y4m");
        const defaultVideoPath = path.join("cypress", "fixtures", "default.y4m");

        const video = fs.readFileSync(defaultVideoPath);

        fs.writeFileSync(webcamPath, video);

        return null;
      },
    });
  },
Run Code Online (Sandbox Code Playgroud)

然后每次你想改变视频就打电话cy.task("changeVideoSource", "video2.y4m");