2

We have a lot of cypress tests in our Angular Project. But we want to use k6 as our new main load testing tool. But also we want to keep our already written cypress tests.

Is it possible to execute cypress tests within k6? e.g run k6 with 1000 VUs but instead of k6 test script, use cypress test scrpts.

Fody
  • 23,754
  • 3
  • 20
  • 37
Tristate
  • 1,498
  • 2
  • 18
  • 38

2 Answers2

1

There's an article here: Using Cypress to automate k6 scripts recording

Lots of steps, but to update for Cypress v10 the syntax for the before:browser:launch hook:

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('before:browser:launch', (browser, launchOptions) => {
        if (browser.isHeaded) {
          try {
            launchOptions.extensions.push(...);
          } catch (error) {
            console.log("extension not available"); //when in headless mode
          }
          return launchOptions;
        }
      })
  },
  // other config
}
Fody
  • 23,754
  • 3
  • 20
  • 37
0

Answer above was a solid suggestion. I used that article indicated there, only slight modifications (i mentioned it on the medium post).

for cypress 10+, under cypress.config.js

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('before:browser:launch', (browser = {}, launchOptions) => {
        console.log(launchOptions.args) // print all current args
        //Mac and Linux path
        //const k6path = "k6Files/k6-Browser-Recorder"
        //Windows path
        const k6path = "C:\\Users\\..."
        if (browser.isHeaded) {
          try {
            launchOptions.extensions.push(k6path);
          } catch (error) {
            console.log("extension not available"); //when in headless mode
          }
          return launchOptions
        }
      })
    },
  },
});

if your using env config files like cypress.dev-config.js then above goes in that e2e section

Rest of instruction on the post should work just fine.