1

I'm trying to concatenate string and integer values in JMeter as below

for(int i in 1..100){
    def cloudItemId="cloudItemId"+i;
    def deviceItemId="deviceItemId"+i;
}

but I'm getting this below error

Response message:Exception: groovy.lang.MissingMethodException: No signature of method:
java.lang.String.positive() is applicable for argument types: () values: []
Possible solutions: notify(), size(), tokenize()

How can Iconcatenate with cloudItemId/deviceItemId

2 Answers 2

1

The issue is + sign is used for mathematic plus in integers and concatenation in Strings

You can concatenate using <<:

for(int i in 1..100){    
    def cloudItemId="cloudItemId" <<i;
    log.info(cloudItemId.toString());
    def deviceItemId="deviceItemId"<<i;
    log.info(cloudItemId.toString());
}

Or call String.valueOf to concat Strings:

for(int i in 1..100){
    def cloudItemId="cloudItemId" + String.valueOf(i);
    log.info(cloudItemId);
    def deviceItemId="deviceItemId"+ String.valueOf(i)
    log.info(cloudItemId);
}
Sign up to request clarification or add additional context in comments.

Comments

1

I cannot reproduce your issue using latest JMeter 5.4.1 (you're supposed to be using the latest JMeter version just in case):

enter image description here

so pay attention to your syntax and suspicious entries in jmeter.log file.

You can also slightly refactor your code to use GStrings and make it more Groovy:

1.upto(100, { i ->
    def cloudItemId = "cloudItemId$i"
    def deviceItemId = "deviceItemId$i"
    log.info('cloudItemId: ' + cloudItemId)
})

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.