in the first thread, I received JSON (format - {"id":6054,"name":"Jmeter created chat","description":"jmeter created test"})
I want to use it in the second thread variable '6054'
I use BeanShell Assertion with code:
${__setProperty(("id":"(.+?)"), ${chat_id)};
but it, of course, doesn't work, please tell me the right way..
many thanks
It won't work because your __setProperty() function call doesn't make sense at all and it's syntactically incorrect
Since JMeter 3.1 you're supposed to use JSR223 Test Elements and Groovy language for scripting
So
Remove your Beanshell Assertion
Add JSR223 PostProcessor as a child of the request which returns the above response
Put the following code into "Script" area:
props.put('chat_id', new groovy.json.JsonSlurper().parse(prev.getResponseData()).id as String)
In 2nd Thread Group access the value using __P() function as:
${__P(chat_id,)}
Demo:
More information regarding what these prev and props guys mean can be found in the Top 8 JMeter Java Classes You Should Be Using with Groovy article
P.S. You may find Inter-Thread Communication Plugin easier to use
Related
Is it possible for a Java request to have a summary report to it. I tried attaching
TPS listener, results tree, results table but could not see the report populated after running in jmeter.
It is not explicitly mentioned jmeter docs, but i assume, It should be supported.But i am not able to see it even after successful run of the test as seen from logs (runTest() method gets called successfully)
It is
The runTest() function is supposed to return a SampleResult and it's your job to call the necessary functions like:
create a new instance
call sampleStart() function when you want to start the measurement
call sampleEnd() function when you want to stop the measurement
call setSuccessful() function to mark the sampler as passed or failed
call setResponsecode() and setResponseData() functions to set response code/response body if needed
See JavaTest and SleepTest example implementations for reference.
You may also find JSR223 Sampler with Groovy easier to use (Java syntax should work in the majority of cases)
I am using Gatling for the first time. I have functional tests that are written in java/cucumber. I want to run these functional tests from a Gatling-scala script to do the performance testing of my application. Is there any way to do so?
The idea is to use the existing functional tests and wrap them around gatling scripts so that they could be executed concurrently for multiple users.
What you want to do is to call a Java method from Scala.
Make sure that the method you want to call is available on the class path Scala sees. Then refer to the method you want to call.
This blog post may help you.
If you are using the Gatling for the first time, have you been considering usage of some other performance tools which can provide you such options? As an analog to Gatling for your case (if you want to create functional tests on Java) and run them later using loading tools I would recommend you to check the Locust.
Using Locust you can write the tests using Java or even Kotlin. You can find the handy tutorial by this link:
https://www.blazemeter.com/blog/locust-performance-testing-using-java-and-kotlin
Another preferable option might be to use Taurus framework which allows you to run JUnit/TestNG tests right away:
https://gettaurus.org/docs/JUnit/
https://www.blazemeter.com/blog/navigating-your-first-steps-using-taurus
Gatling is primarily for http testing. what I would do is to call java code from within a gatling test that will return me a value that I check for ex: I return a boolean from a java code below for doing performance test(same also for functional test which needs extending GatlingHttpFunSpec instead of Simulation class). Also will need to use a dummy endpoint (like a health check url which will always return 200).
val myJavaTest: MyJavaTest = new MyJavaTest()
val baseURL="http://localhost:8080"
val endpoint_headers=Map("header1" -> "val1")
val endPoint="/myurl/healthcheck"
setUp(scenario("Scenario ")
.exec(
http("run first test")
.get(endpoint)
.headers(endpoint_headers)
.check(bodyString.transform(str => {
myJavaTest.runTest1()//should return boolean
}).is(true)))
.inject(atOnceUsers(1))).protocols(http
.baseURL(baseURL))
I am new to OpenERP and playing around.
My plan is to connect OpenERP to a SOAP Webservice. Hence, OpenERP does only support XML-RPC I will write a converter in Java. I am able to make a call from Java to OpenERP but I do not know how I should start with the other direction.
My goal is to change the Manufacturing Workflow. After "Confirm Production" it should send some data via XML-RPC to my Java xmlrpc Server.
I created a new node and add a Server Action with the following code:
import xmlrpclib
sock = xmlrpclib.ServerProxy('http://localhost:8080/xmlrpctest/xmlrpc')
This gives me the error
NameError: name 'xmlrpclib' is not defined
I thought the xmlrpclib is always included in OpenERP.
I would be glad if somebody could tell what the right approach is to call from OpenERP over XML-RPC a java server.
Thanks in advance.
As Andrei says, this isn't an OpenERP question, this is just a general python question. You will need to look at the python SOAP libraries to make SOAP calls to your java web-service.
As a caution though, think carefully about hooking the SOAP call into the workflow as you will get all your transactions failing in OpenERP if the java server is down. Unless you need them to be synchronous would be better to use a queue (Celery, Rabbit etc) and just dump the message into the queue. You can use the OpenERP scheduled tasks to kick of a synchronise process when you need.
Don't do it in a server action. You can read in the OpenERP documentation (the link I already sent you :)) the following
The code is executed using the exec function of python, which is run in the dictionary namespace with variables: object,time,cr,uid,ids
Well, I think that's not completely true - actions in OpenERP are executed trough the tools.safe_eval.safe_eval() method. From the doc string of this method:
"""safe_eval(expression[, globals[, locals[, mode[, nocopy]]]]) -> result
System-restricted Python expression evaluation
Evaluates a string that contains an expression that mostly
uses Python constants, arithmetic expressions and the
objects directly provided in context.
This can be used to e.g. evaluate
an OpenERP domain expression from an untrusted source.
Throws TypeError, SyntaxError or ValueError (not allowed) accordingly.
Without entering in the details, it's a restricted execution. Instead of this do the following:
Create your own module
Create a class which inherits from mrp.production. I mean, do
_inherit = 'mrp.production'
inside your class.
Override in this class the method executed after "Confirm Production" (whatever this is).
Do what you need with your rpc server in this new method.
Don't forget to call super()
'xmlrpclib' was introduced into the Python standard library at Python 2.2, and in version 3.0 was renamed to 'xmlrpc' and reorganised.
I'm trying to use Beanshell in a java application to execute "addon" files supplied by a user. Since the "main" code of the addon is called in a repeating loop, some addons need to use global variables initialized outside the scope of this code in order to keep track of things that require more than one loop cycle. I'm trying to do this by setting up a beanshell interpreter as
interpreter.eval("float xPositions;");
while(condition) {
interpreter.eval("xpositions++;");
}
The problem is, by the time beanshell gets the second eval, it's forgotten that the variable exists. Is there a way to stop it doing this?
This is the way to go: interpreter.set("myVarName", myValue);
Btw: There is a bugfix version of beanshell, called beanshell2 at http://code.google.com/p/beanshell2 available.
I have a javascript function (very big one!) that I need its functionality in a Java (Groovy) class. It is a simple calendar converter. I can rewrite it in groovy but just want to know if it is possible to call javascript function from a java (groovy) method? I guess functional testing libraries like selenium and Canoo should have something like this, am I right?
PS: I don't want to wake up a real-world browser in order to use its JS runtime env.
Thanks,
As mentioned in the other answers, it is possible to use the Scripting API provided as part of the javax.script package, available from Java 6.
The following is a Groovy example which executes a little bit of Javascript:
import javax.script.*
manager = new ScriptEngineManager()
engine = manager.getEngineByName("JavaScript")
javascriptString = """
obj = {"value" : 42}
print(obj["value"])
"""
engine.eval(javascriptString) // prints 42
It is not necessary to call a browser to execute Javascript when using the Scripting API, but one should keep in mind that browser-specific features (probably the DOM-related functionalities) will not be available.
You can use Rhino, an implementation of JavaScript language in Java. Here is example of calling JavaScript function from java, but you can do it from groovy also.