smicyk / groovy-jmeter

A Groovy-based DSL for building and running JMeter test plans from command line and more.
Apache License 2.0
13 stars 1 forks source link

arguments from different files #73

Closed AntonioSun closed 2 years ago

AntonioSun commented 2 years ago

I planned but haven't got around to test it yet, so let me ask first.

Suppose I have several files that has only arguments definitions in them:

    arguments {
      argument(name: 'xxx', value: 'yyy')
      . . . 
    }

If I use https://github.com/smicyk/groovy-jmeter/wiki/reference#insert to insert them one after another, will the argument definitions accumulate (desired)?

smicyk commented 2 years ago

If you mean something like:

plan {
  arguments {
      insert 'arguments1.groovy'
      insert 'arguments2.groovy'
  }
}

where

arguments1.groovy

fragment {
   argument name: 'test1', value: 'test1'
   argument name: 'test2', value: 'test2'
}

arguments2.groovy

fragment {
   argument name: 'test3', value: 'test3'
   argument name: 'test4', value: 'test4'
}

and the result would be:

plan {
  arguments {
     argument name: 'test1', value: 'test1'
     argument name: 'test2', value: 'test2'
     argument name: 'test3', value: 'test3'
     argument name: 'test4', value: 'test4'
  }
}

Then no, it will not work like that.

I think the result might be something like that:

plan {
  arguments {
     argument name: 'test2', value: 'test2'
     argument name: 'test4', value: 'test4'
  }
}

So only last element from fragment is added. I might look at it since it might work differently but I doubt it will be easy to fix.

AntonioSun commented 2 years ago

Thanks for looking into it.

What if we don't use Test Plan argument but User Variables elements? Can the insert be granular enough to add them all into a single definition?

Since such feature is not available out of the box, so I'm thinking making my end goal clear is important -- I was hoping to achieve modularized control of what we are testing. I.e., switching from site a to site b, or DB from customer a to customer b, all is needed is to make a switch of the whole set of variables and replace them with a new set, by just replacing one insert file.

This is what I was trying to achieve. It doesn't not have to be done this way, if there is a good way to do it, then I'm all good.

smicyk commented 2 years ago

OK. Since I like examples lets make some examples:

main.groovy


plan {
    insert "$var_variablesFile"

    group {
        http path: '${site}/api/books', method: 'GET'
        // other stuff
    }
}

variables_set1.groovy


fragment {
    variables {
        variable name: 'company', value: 'Big Company'
        variable name: 'site', value: 'bigcompany.com'
    }
}

variables_set2.groovy


fragment {
    variables {
        variable name: 'company', value: 'Small Company'
        variable name: 'site', value: 'smallcompany.com'
    }
}

then when you execute your script with variable __var_variablesFile__ you can have different User Defined Variables for each script.

# in this case the request is for smallcompany.com/api/books
groovy main.groovy -Vvar_variablesFile=/path/to/variables_set2.groovy

In other words changing var_variablesFile on command line will load particular user variables.

The other way would be to use Module Controller which unfortunately is not implemented right now.

Hope it helps.

AntonioSun commented 2 years ago

Yeah, that'll work too. I was thinking to be able to switch sites and DBs individually, and there will be variables the don't need to be changed despite the switches, but switching all of them at once will be not too bad either.

Thanks