kowalpy / Robot-Framework-JMeter-Library

Robot Framework and JMeter integration
16 stars 11 forks source link

Query: How to pass values to the user defined variable in jmeter's jmx file via robot framework #6

Open chidambaranathan-r opened 3 years ago

chidambaranathan-r commented 3 years ago

robot-framework version = 3.2.2 ; Python version = 3.9.0 ; jmeter version = 5.4.1

I have a JMX file in which "Number of Threads (users):" is defined as a variable "${__P(threads)}.

In robot-framework, how to pass values to this user defined variable in the jmx file via keywords defined in JMeterLib.

Example: How to include the same in the below keyword syntax of JMeterLib:- run jmeter D:/apache-jmeter-2.12/bin/jmeter.bat D:/Tests/Test1Thread1Loop.jmx D:/Tests/output1.jtl

I tried the below:

run jmeter ${jmeter_install_path} ${jmeter_jmx_path} ${jmeter_log_path} -Jthreads=10

but it thrown below error,

"AttributeError: module 'string' has no attribute 'split'"

Can I get some clue on how to solve this?

kowalpy commented 3 years ago

Try not using equal sign, for example: -Jthreads 10. Let me know if it helped.

chidambaranathan-r commented 3 years ago

Without using equal sign it works. Thanks. But I was getting error "AttributeError: module 'string' has no attribute 'split'".

After analysis, it is found that this error occurred because the jmeter library for robot framework https://github.com/kowalpy/Robot-Framework-JMeter-Library is running in Python3 version in my test environment, but library is originally developed in Python 2.7.5 version. In nutshell, it due to python version compatibility.

And so, there is a particular command in the class "JMeterClasses.py" that was not recognized in Python 3 version due to which the error "AttributeError: module 'string' has no attribute 'split'" is thrown.

Then updated the below method in "JMeterClasses.py".

Old: def listOtherParams(self): self.params = [] if not self.paramsStr == "": self.params = string.split(self.paramsStr)

Updated (string is modified as str, as highlighted below): def listOtherParams(self): self.params = [] if not self.paramsStr == "": self.params = str.split(self.paramsStr)

It worked for me after modifying the above method.

One more query: Can we pass more than one variable fro JMX file. For example "${P(threads)}" and ""${P(token)}? I tried but it throws error like "Keyword 'JMeterLib.Run Jmeter' expected 3 to 4 arguments, got 5.".

It seems currently it is restricted to have only max 4 arguments. Any idea or way forward to include more variable that is defined in the JMX configuration file?