Coder Social home page Coder Social logo

groovy-harventer's Introduction

Groovy Harventer

Converts .HAR files to Groovy JMeter DSL scripts.

The HTTP Archive format is used store communication data (HTTP protocol) between the server and the client.

The .HAR files can be obtained by various tools (including all major browsers).

Prerequisites

Before start, you should have:

How to start

Download latest version from releases page and unpack in any folder. Go to bin folder and execute following command:

$ harventer -i yourharfile.har -o yourdslscript.groovy

If in trouble try check 'help' option:

$ harventer --help

usage: harventer [options]
 -c,--compact                             If present the param and headers
                                          will be generated in compact
                                          form
    --dsl-version <arg>                   Specify which DSL version to use
                                          for generated script
    --exclude-headers <pattern>           Regex pattern for header name to
                                          exclude (by default all headers
                                          are excluded)
    --exclude-types <pattern>             Regex pattern for response
                                          content type to exclude (by
                                          default css, javascript, images
                                          and binary types are excluded)
    --exclude-urls <pattern>              Regex pattern for URL to exclude
                                          (by default .css, .js, .bmp,
                                          .css, .js, .gif, .ico, .jpg,
                                          .jpeg, .png, .swf, .woff,
                                          .woff2)
 -h,--help                                Show help
 -H,--header-variables <param=variable>   Substitute header with variable
                                          (applies to request headers)
 -i,--input-file <file>                   Input *.har file
    --include-headers <pattern>           Regex pattern for header name to
                                          include
    --include-types <pattern>             Regex pattern for response
                                          content type to include
    --include-urls <pattern>              Regex pattern for URL to include
    --loops=<number>                      Loops number for users
 -o,--output-file <file>                  Output *.groovy file
 -P,--param-variables <param=variable>    Substitute param with variable
                                          (applies to request params)
    --ramp-up <number>                    Ramp up time for test plan
 -t,--think-time                          If present each HTTP request has
                                          think time based on real
                                          execution
 -U,--url-variables <param=variable>      Substitute part of URL with
                                          variable
    --users <number>                      Number of users for default
                                          group

Examples

Below you can find several examples of command execution:

  • the converter excludes all headers for HTTP request, but you can provide which you want to have in the script (use '|' to put several names)

    $ harventer -i yourharfile.har -o yourdslscript.groovy --include-headers "X-CSRF-TOKEN|Host"

    The output from the command should look like code below (the converter adds header X-CSRF-TOKEN and Host if they exist):

    start {
        plan {
            summary(path: 'yourdslscript.jtl', enabled: true)
            group(users: 1, rampUp: 1, loops: 1) {
    
                // defaults comes from the first request available in .HAR file
                defaults(protocol: 'http', domain: 'localhost', port: 80)
    
                http('POST /app') {
                    // headers are automatically added to http request
                    headers {
                        header(name: 'X-CSRF-TOKEN', value: '2429304892384092384093')
                        header(name: 'Host', value: 'localhost')
                    }
                    params {
                        param(name: 'param1', value: 'value1')
                    }
                }
            }
        }
    }
  • the --haeder-variables option creates JMeter variables placeholders for matching headers

    $ harventer -i yourharfile.har -o yourdslscript.groovy --include-headers "X-CSRF-TOKEN" --header-variables "X-CSRF-TOKEN=var_csrfToken"
    

    The output is very similar to previous one but this time, values for headers comes from defined variable:

    start {
        plan {
            summary(path: 'yourdslscript.jtl', enabled: true)
            group(users: 1, rampUp: 1, loops: 1) {
                variables {
                    // variable defined on the command line
                    variable(name: 'var_csrfToken', value: '')
                }
    
                // defaults comes from the first request available in .HAR file
                defaults(protocol: 'http', domain: 'localhost', port: 80)
    
                http('POST /app') {
                    // headers are automatically added to http request
                    headers {
                        header(name: 'X-CSRF-TOKEN', value: '${var_csrfToken')
                    }
                    params {
                        param(name: 'param1', value: 'value1')
                    }
                }
            }
        }
    }

    The options --param-variables works pretty much the same but for HTTP parameters

  • Next example shows how to automatically add users, ramp up and loops for you test plan, with --users, --ramp-up and --loops options:

    $ harventer -i yourharfile.har -o yourdslscript.groovy --users 10 --rampUp 60 --loops 10
    start {
        plan {
            group(users: 10, rampUp: 60, loops: 10) {
                // rest of script
            }
        }
    }
  • The --think-time option add small wait time between each sample execution. Converter extracts times from .HAR files. With this option the script can more precisely simulate real user interaction.

    $ harventer -i yourharfile.har -o yourdslscript.groovy --think-time

    Output from the command:

    start {
        plan {
            group(users: 1, rampUp: 1, loops: 1) {
                http('POST /app') { }
                flow(name: 'Think Time', action: 'pause', duration: 0) {
                    uniform_timer(name: 'Pause', deloay: '716', range: 100)
                }
    
                http('GET /app/form') { }
                flow(name: 'Think Time', action: 'pause', duration: 0) {
                    uniform_timer(name: 'Pause', deloay: '300', range: 100)
                }
            }
        }
    }

groovy-harventer's People

Contributors

smicyk avatar

Watchers

 avatar

groovy-harventer's Issues

Suggestions

  • Remove version from the @Grab('net.simonix.scripts:groovy-jmeter:0.11.0') so it will always picks the latest version.
  • Remove the simple {} wrapping layer so the the script more looks like the normal examples
  • Remove the loop(count: 1) layer so again the the script more looks like the normal examples
  • Or better add/move the loop control into the group() definition, as to control the load, JMeter also has/need a third parameter apart from users & rampUp -- how long the script should run, or how many iterations.

thanks for your consideration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.