简体   繁体   中英

How do you get Cypress and JMeter to work simultaneously

I'm trying to get Cypress Paired with JMeter. My current task is to get results (Performance times) from the cypress tests, then compare them with the results with the load. My first objective after writing the tests was to get cypress to launch the JMeter scripts I have then while those are running, execute the tests.

My first issue was trying to run an exec command, however, cypress keeps throwing an error saying exec is not a function. Error: TypeError exec is not a function

context('Experimental', function () {
    it("Execute Command Line", function () {
        var exec = require('child_process').exec, child;
    
        child = exec('java -version', // Just an example
            function (error, stdout, stderr) {
                console.log('stdout: ' + stdout);
                console.log('stderr: ' + stderr);
                if (error !== null) {
                     console.log('exec error: ' + error);
                }
            });
         child();
    })
})

I've also tried with

var { exec } = require('child_process');

My second issue was trying to run an exec command with cypress. However, now it waits for the command to finish instead. This is not erroring, but more of the idea that it's running the JMeter and waiting for that to finish before continuing with the tests as load is being put on the server.

context('Experimental', function () {
    it("Execute Command Line", function () {
        cy.exec('jmeter -n -t C:/test.jmx -l c:/results.csv', {timeout:600000})
        cy.log('Something')
        cy.pause()
    })
})

If I can find out how to run the command line while having the scripts run, this would be helpful as I'll need to implement a similar function for spinning up an environment. Any plugins or modules would help as well. I'm very inexperienced with Javascript.

Cypress exec task needs to be executed from it context which is synchronous so I wouldn't say it's possible as it's not compatible with Cypress test building model.

Have you considered orchestrating everything from JMeter instead? For example you can use setUp Thread Group for spinning up the environment, one Thread Group for creating the load and another Thread Group for checking the frontend via Cypress Tests. By the way, there is JMeter integration with Selenium browser automation framework via WebDriver Sampler .

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