【发布时间】: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?