I want to create Beanshell script to start the business process for single order.
Thanks in Advance.
Your beanshell should be something like this :
BusinessProcessService processService =
(BusinessProcessService) Registry.getApplicationContext()
.getBean("businessProcessService");
OrderProcessModel businessProcessModel =
processService.createProcess(PROCESS_CODE, PROCESS_NAME);
processService.startProcess(businessProcessModel);
Make sure to put a proper PROCESS_CODE, a proper PROCESS_NAME and set any useful property for businessProcessModel.
Related
I have a WO in Maximo 7.6.1.1.
When a user updates the Service Address, I want to invoke an autoscript that has an Object Launch Point on the WORKORDER object.
Is there a way to invoke an autoscript (that has an object launch point on the WORKORDER object) when the Service Address is updated?
You should see if mbo.getOwner() returns something and if that something.getName() is WORKORDER and, further, the work order you are expecting it to be. Subject to all that, you can invoke that other autoscript with code like this:
from java.util import HashMap
lpVars = HashMap()
lpVars.put("mbo",mbo.getOwner())
#repeat the last line for any other implicit/explicit variables your target
#script is going to use / expect to be defined
service.invokeScript("YOURSCRIPTNAME", lpVars)
someVar = lpVars.get("someVarDefinedInYOURSCRIPTNAMEWhenItEnded")
Note the work with the lpVars variable. I use it to store the "implicit"/"explicit" variables (e.g. "mbo") that the script I'm calling will expect to be defined. Basically, I'm doing the setup a launch point normally does, since my code is the launch point. Then, since I'm the launch point, I have access to whatever variables were defined when the script ended by Maximo adding them to / updating them in lpVars.
You can create reusable "library" scripts that you can call directly as Preacher explained. See IBM example here: https://www.ibm.com/support/knowledgecenter/SSFGJ4_7.6.0/com.ibm.mbs.doc/autoscript/c_example_reuse.html
So you could have your WO object launchpoint call the library script and your SA object launchpoint calling the same. You then just need to make change to one script if needed and that's great.
I don't believe you can. An object launch point is all about telling Maximo which object to monitor for the following event(s), not exactly about which object to launch the script on (though, for various reasons, those two are necessarily tied together).
What you can do, though, is put your launch point on the service address as you really do want, but then in your script fetch the on-screen/in-memory work order that you want to do something with and do that. This is done through the getOwner() method call or the special ":owner" (maybe with the ampersands, I can't remember) relationship reference.
This is the solution I came up with:
mboName=mbo.getName()
if mboName == 'WOSERVICEADDRESS':
mboWO = mbo.getOwner()
elif mboName == 'WORKORDER':
mboWO=mbo
sax = mboWO.getDouble("SERVICEADDRESS.LONGITUDEX")
say = mboWO.getDouble("SERVICEADDRESS.LATITUDEY")
if sax and say:
mboWO.setValue("longitudex", sax)
mboWO.setValue("latitudey", say)
elif mboWO.getString("ASSETNUM") and mboWO.getBoolean("ASSET.PLUSSISGIS") == 1:
mboWO.setValue("longitudex", mboWO.getDouble("ASSET.longitudex"))
mboWO.setValue("latitudey", mboWO.getDouble("ASSET.latitudey"))
elif mboWO.getString("LOCATION") and mboWO.getBoolean("LOCATION.PLUSSISGIS") == 1:
mboWO.setValue("longitudex", mboWO.getDouble("LOCATION.longitudex"))
mboWO.setValue("latitudey", mboWO.getDouble("LOCATION.latitudey"))
else:
mboWO.setValue("longitudex", None)
mboWO.setValue("latitudey", None)
The script has launch points on multiple objects:
I am trying to do setproperty across multiple threads in the same threadgroup, the postprocessor set new variable using setproperty, so that It can be accessed across multiple threads.
In Beanshell preprocessor, I'm having below line of code.
${__setProperty("url", "youtube")};
Under thread Group I'm having Beanshell post processor, having below one line in postprocessor.
${__setProperty("url", "google")};
under thread group, I have Http Sampler, in hostname field I have given ${__property(url)}.com
The Aim is, when it executes first time, the URL will be google.com and when first threads complete than
the URL becomes youtube.com
But the setProperty only set google, and the second one in postprocessor was not working.
Refer the below Image for details, it shows how I created the element in Jmeter.
enter image description here
Note: This was just a sample use case, but I have complex example, but answering to this question will help me to add the logic in complex script.
Thanks
So is the goal that the very first thread to complete will change the URL for all subsequently created threads?
My understanding of the documentation is that you can't change the value of a property inside the thread-group:
Properties can be referenced in test plans - see Functions - read a property - but cannot be used for thread-specific values.
(see http://jmeter.apache.org/usermanual/test_plan.html#properties)
My assumption is that each thread in a thread-group gets a copy of the properties. If you change the value of the property inside the thread group, then you are actually changing the copy for that particular thread. Since you are changing it in the post-processor, the thread is very likely just about to be disposed, resulting in your change being lost. After disposal a new thread is created but with the original value of the property.
So what you need to do is figure out how to change the value outside of the thread-group.
I have done something similar in my own tests whereby I am changing the value of a property in the middle of the test, and the value is picked up immediately by all of the active thread-groups, resulting in each new thread created from that point forward getting the new value. I am doing this by using the Beanshell Server: https://jmeter.apache.org/usermanual/best-practices.html#beanshell_server
In my specific case I use jenkins job that calls a shell-script which connects to the beanshell-service running on the local-host:
java -jar ${jmeter_home}/apache-jmeter-5.0/lib/bshclient.jar localhost 9000 ${test_plan_home}/update_Prop.bsh "${property}" "${value}"
where my update_prop.bash file is simply:
import org.apache.jmeter.util.JMeterUtils;
JMeterUtils.getJMeterProperties().setProperty(args[0],args[1]);
You would not need to use Jenkins or anything like that, though - if you setup your JMeter Process to include the Beanshell-server (see the link above) then you can simply replace the code in your post-processor:
${__setProperty("url", "google")};
with the code to connect to the beanshell server and execute that command there instead:
exec("./updateprop.bash url google");
JMeter properties are global therefore once you set the property it is available for all threads
Each JMeter thread (virtual user) executes Samplers. Pre and Post processors are obeying JMeter Scoping Rules Looking into your test plan the execution order is following:
Beanshell PreProcessor
HTTP Request Sampler
Beanshell PostProcessor
therefore HTTP Request sampler will never hit youtube (unless you run into a race condition due to concurrency) because PreProcessor will set the URL back to google
It is recommended to use JSR223 Test Elements and Groovy language for scripting since JMeter 3.1
It is NOT recommended to inline JMeter Functions and/or variables into scripts, you need to either use "Parameters" section or go for code-based equivalents instead so you need to replace this line:
${__setProperty("url", "youtube")};
with this one:
props.put("url", "youtube");
Can i print session id (which i extract by Regex in previous request response)
in logs by JSR223 postProcessor sampler(groovy)
Thnks in advance
Your variable can be access using vars, for example if you save it as sessionId:
log.info("Session id=" + vars.get("sessionId"));
vars - (JMeterVariables) - gives read/write access to variables
log - (Logger) - can be used to write to the log file
Be aware that it is recommended to use JMeter's built-in test elements and void scripting where possible so I would rather suggest considering using __log() function in order to print the value like:
Double check that your variable is defined and has the value using Debug Sampler and View Results Tree listener combination
Once you verify that the variable is there you can print it to the log using the following syntax:
${__log(${your_variable_reference_name)}
If you still want to proceed with Groovy - the equivalent syntax would be:
log.info(vars.get('id'))
See Top 8 JMeter Java Classes You Should Be Using with Groovy for more information if needed
I am creating an application where I pass in one or more test cases to the TestLoader that then get run.
I can run and add the testcase to the suite like this
suite1 = unittest.TestLoader().loadTestsFromTestCase(mymodule.Testcase01)
suite = unittest.TestSuite([suite1])
However, what I actually want to do is something like this
myTestcaseAsString="mymodule.Testcase01"
suite1 = unittest.TestLoader().loadTestsFromTestCase(myTestcaseAsaString)
suite = unittest.TestSuite([suite1])
What I want to happen is that the value of myTestcaseAsaString is passed into loadTestsFromTestCase as if it was hard coded like the first example
Is that possible? (my long term goal is to be able to add multiple testcases to teh same suite - if that makes a difference)
Thanks
Grant
This is what I ended up doing
suite2 = unittest.TestLoader().loadTestsFromTestCase(eval(testcasemodule))
I have full control over the testcasemodule value
Thanks
Grant
I may be going about this in the completely wrong way, but how do I pass a dynamic variable to a bunch of requests within the same testsuite in SoapUI?
My first test step is a Groovy script. I need to generate a random account name, and then use it in all my other requests. There are about 20 other requests. I initially thought I could just loop the testsuite, but it is not working.
This is my groovy script at the beginning:
Random random = new Random()
def randUserAccount = "testAccount"
int max = 100000
randnum = random.nextInt(max+10000)
randUserAccount += randnum
log.info " Creating account: $randUserAccount"
Then in each request step, I have things like this:
<ns:CreateAccountRequest>
<accountID>${randUserAccount}</accountID>
...
or
<ns:PurchaseRequest>
<accountID>${randUserAccount}</accountID>
...
The account is null when I actually send it, and of course that gives errors on the server side. How do I really get the variable to persist across all the requests in the testsuite?
Thanks in advance for any hints!
You can use the context, I believe. You can definitely use it between requests in a test, but I also think it will work between tests in a suite.
context.setProperty("randUserAccount", randUserAccount)
Then use the syntax you specified in the actual requests.
Let me know if this doesn't work. You can also use 'properties' to do this, but it is a little more work.
or you can create a variable in property then set the value through set property as mentioned above..
for every tag jus right click and check the your project varaible it will automatically insert the code..
Hope it help