简体   繁体   English

如何让 Cypress 和 JMeter 同时工作

[英]How do you get Cypress and JMeter to work simultaneously

I'm trying to get Cypress Paired with JMeter.我正在尝试让赛普拉斯与 JMeter 配对。 My current task is to get results (Performance times) from the cypress tests, then compare them with the results with the load.我当前的任务是从 cypress 测试中获取结果(性能时间),然后将它们与负载结果进行比较。 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.编写测试后,我的第一个目标是让赛普拉斯启动 JMeter 脚本,然后在这些脚本运行时执行测试。

My first issue was trying to run an exec command, however, cypress keeps throwing an error saying exec is not a function.我的第一个问题是尝试运行 exec 命令,但是,cypress 不断抛出错误,说 exec 不是 function。 Error: TypeError exec is not a function错误:TypeError exec 不是 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.我的第二个问题是尝试使用 cypress 运行 exec 命令。 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.这不是错误,而是更多的想法是它正在运行 JMeter 并等待它完成,然后再继续测试,因为负载正在加载到服务器上。

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.如果我可以在运行脚本的同时了解如何运行命令行,这将很有帮助,因为我需要实现类似的 function 来启动环境。 Any plugins or modules would help as well.任何插件或模块也会有所帮助。 I'm very inexperienced with Javascript.我对 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.赛普拉斯exec任务需要从同步的上下文中执行, it我不会说这是可能的,因为它与赛普拉斯测试构建 model 不兼容。

Have you considered orchestrating everything from JMeter instead?您是否考虑过编排 JMeter 中的所有内容? 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.例如,您可以使用setUp 线程组来启动环境,一个线程组用于创建负载,另一个线程组用于通过赛普拉斯测试检查前端。 By the way, there is JMeter integration with Selenium browser automation framework via WebDriver Sampler .顺便说一句,JMeter 通过WebDriver SamplerSelenium浏览器自动化框架集成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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