【问题标题】:Cypress browser support赛普拉斯浏览器支持
【发布时间】:2021-12-21 02:22:26
【问题描述】:

在默认的 cypress 框架中,我们有 plugins.js -> index.js 下面的代码,他们只列出了 chromium 和 electron 浏览器。我们是否需要添加更多,或者这样可以吗? 从这张图看,cypress 好像只支持铬和电子?但是,当我们运行 99% 的案例时,我们会在 Chrome 中运行它。默认情况下选择 chrome。


/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

const cucumber = require("cypress-cucumber-preprocessor").default;

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
 * @type {Cypress.PluginConfig}
 */
// eslint-disable-next-line no-unused-vars

module.exports = (on, config) => {
  require("cypress-mochawesome-reporter/plugin")(on);
};
module.exports = (on, config) => {
  on("file:preprocessor", cucumber());

  // cypress/plugins/index.js

  on("before:browser:launch", (browser = {}, launchOptions) => {
    console.log(launchOptions.args);
    if (browser.family === "chromium" && browser.name !== "electron") {
      launchOptions.args.push("--start-fullscreen");
      launchOptions.args.push("--window-size=1400,1200");

      return launchOptions;
    }

    if (browser.name === "electron") {
      launchOptions.preferences.fullscreen = true;

      return launchOptions;
    }
  });

  module.exports = (on, config) => {
    on("before:browser:launch", (browser, launchOptions) => {
      if (browser.name === "chrome" && browser.isHeadless) {
        launchOptions.args.push("--disable-gpu");
        return launchOptions;
      }
      
    });
  };

  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
};



【问题讨论】:

  • 你用来运行测试的命令是什么?
  • 我第一次使用:npx cypress open。在此之后我从柏树窗口运行
  • 您可以从这里更改可用的浏览器 - imgur.com/a/D1hIbMF。使浏览器在下拉列表中可用。您必须在本地计算机上安装该浏览器。
  • 是的,我知道。我的确切问题是,我们应该在 plugins.js->index.js 文件中存储什么?它应该是什么样子?如果我们可以从 imgur.com/a/D1hIbMF 更改它,为什么我们需要 plugins.js->index.js?

标签: node.js browser cypress


【解决方案1】:

在 cypress 窗口的右上角,您应该能够选择要运行的浏览器。 您还可以在该 index.js 文件中指定要使用的浏览器。这是一个例子:

module.exports = (on, config) => {
// inside config.browsers array each object has information like
// {
//   name: 'chrome',
//   channel: 'canary',
//   family: 'chromium',
//   displayName: 'Canary',
//   version: '80.0.3966.0',
//   path:
//    '/Applications/Canary.app/Contents/MacOS/Canary',
//   majorVersion: 80
// }
return {
  browsers: config.browsers.filter((b) => b.family === 'chromium'),
 }
}

请参阅赛普拉斯文档了解更多信息:https://docs.cypress.io/guides/guides/launching-browsers#Customize-available-browsers

【讨论】:

  • 是的,我知道。我的确切问题是,我们应该在 plugins.js->index.js 文件中存储什么?它应该是什么样子?如果我们可以从 cypress 窗口更改它,为什么我们需要 plugins.js->index.js?
  • 将其添加到 index.js 文件时,您正在设置不使用 cypress 窗口时希望在其中运行测试的默认浏览器。如果您愿意从测试运行程序中更改它,那么您不需要在 index.js 文件中做任何事情@Luna
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
  • 2021-10-30
  • 1970-01-01
相关资源
最近更新 更多