Closed AntonioSun closed 2 years ago
I assume you use mockserver from examples/mockserver.
So if you want to run your script with docker command you need to add the container to the same network as mockserver. Your script should be based on examples/docker as it is more what you want to achieve. The crucial part is network parameter --network network-books in your docker command (check run.sh in docker example).
Also host for mockserver in your script should be mockserver as it is named in docker compose file. The IP approach might work if you change network type to host for mockserver and docker in your command. In the examples I use the separate network so I can use names instead of IP which is more convenient.
Next thing, you should verify if your all command variables are properly put in the script. The groovy string interpolation only works if ${} is put in double quotes. So this:
argument(name: 'var_host', value: '${jmt_host}')
should be this
argument(name: 'var_host', value: "${jmt_host}")
Hope that helps
Thanks a lot for your detailed explanation!
Just want to confirm:
Is this domain: '${var_host}'
a typo or somehow it works even if the ${}
is not put in double quotes?
Ah ok, so you should look at https://github.com/smicyk/groovy-jmeter#groovy-as-dsl.
So basically you have two types of variables substitutions, the one for groovy variables and one for jmeter variables. Since jmeter and has same syntax to substitute it can be confusing. In general the rule is if you want groovy substitution you should use double quotes, in any other case you should use single quotes.
In your case when you have:
argument(name: 'var_host', value: "${jmt_host}")
you define var_host variable based on groovy variable jmt_host and this substitution is only available during test plan build phase.
then
defaults(protocol: 'http', domain: '${var_host}', port: 1080)
you use __var_host__ variable define before during test plan execution.
Note, that groovy substitution you don't have use string interplation to get variable and just use the variable name. It depends what you want to actually create as a variable.
Thanks a lot for your detailed explanation!
In such case, would the following jmt_user_xx
better be using single quotes, if I don't want to hard-code them?
I'm not sure I understand, the example use jmt_user_nm and jmt_user_pw as variables from command line. In that case they must be in double quotes otherwise they will not be substituted by groovy.
You explained well. thx.
I was just confused where is the DSL part and where is the groovy string part.
Another example,
why the jmt_users
in this case not in double quotes, and not in ${}
either.
(I should have closed it awhile back)
Yes, so jmt_users without quotes means you use the value alone, but with quotes you create a string. Example assume jmt_users=5, then:
# user will have just value 5 as integer
group(users: jmt_users)
but
# the var_user_description variable will have value 'I have 5 users to run' as a string
argument(name: 'var_user_description', value: "I have ${jmt_user_nm} users to run")
https://github.com/smicyk/groovy-jmeter/blob/8e22a6230524704da27dae5aca5ebf686166ddf9/examples/commandline/script.groovy#L7-L12
Based on that, I'm running my script of https://gist.githubusercontent.com/AntonioSun/d3068084f03fb5e5f2a63b9f3e73c5e1/raw/9e3a7e6922047aedf0520e22f74156e26f28519d/commandline.groovy
and this is what I got:
This is not the first time that I'm seeing 100.00% Err when running groovy-jmeter scripts. In fact all of them are, as of now.
I posted the execution log here. This is actually my 3rd run, previously every line has problems, now at least the top few lines are OK.
The converted jmeter script runs fine in jmeter. I posted the jmeter script here -- https://gist.githubusercontent.com/AntonioSun/d3068084f03fb5e5f2a63b9f3e73c5e1/raw/77f4d18a970c6d8c2bdc57177649cb1bd8290094/commandline.jmx