简体   繁体   中英

Cypress browser support

In the default cypress framework, we have plugins.js -> index.js the below code, and they've listed only chromium and electron browsers. Do we need to add more or is this okay the way it is? From this picture, it looks like cypress supports only chromium and electron? But while we run 99% of cases we run it in Chrome. It is by default choosing 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
};



In the top right corner of the cypress window you should be able to choose which browser you want to run. You can also specify which browser you want to use in that index.js file. Here is an example:

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'),
 }
}

See cypress docs for more: https://docs.cypress.io/guides/guides/launching-browsers#Customize-available-browsers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM