Generate a variable in Groovy JMeter - groovy

I have a Thread Group wherein I have three samplers. They are HTML Requests. The first one returns a person and gives me the name, age and address. The second one changes the attribute name of the person but has no response.
The third sampler is the same as the first.
The second sampler isn't working and doesn't change the name.
I want a failure message like: "The name of the person was $(name1) and should be changed to $(name2), but the name is $(name3)" or something like that.
I do the whole things with Groovy so is there any way to generate variables with the output of the first and third request and the input of the second?

Most probably you're looking for Response Assertion, you can conditionally mark samplers as failed depending on various criteria. It might be the case that you won't even need scripting like.
Just add Response Assertion as a child of 3rd request and configure it to expect ${name3} variable to be present in the response (you can use Perl-5 style regular expressions for this as well) and if the name will not be present - the sampler will get failed and you will see the relevant failure message
More information: How to Use JMeter Assertions in Three Easy Steps

I do not think you can do it the way you describe it, because samplers are processed sequentially, so you can not process first, third and go to second request. You might want to re-evaluate your approach.

Related

NetSuite Phone Number Formatting

I am trying to implement automatic phone number formatting into NetSuite I am having some issues getting my script to work. Basically if someone enters a phone number into a customer record, "1234567890" for example, it will automatically format to "(123) 456-7890". You can see my script below along with the error message I receive when creating a new script record.
Fail to evaluate script:
{"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing ; before statement (SS_SCRIPT_FOR_METADATA#21)","stack":[]}
Why do you need a script for this? NetSuite already does this, based on the Phone Number Format setting at Setup > Company General Preferences. Check you have this field set correctly according to your preference.
If for whatever reason it turns out you do need a script for this, there are several issues with the script you posted:
There is a syntax error - mismatched parentheses/braces. Your code editor is trying to show you that with the red brace on line 8 and the red squiggly underline on the last parenthesis (line 23).
NetSuite record level client scripts must implement an entry point function. For formatting phone numbers this would be a fieldChanged() entry point. You would need to wrap the logic contained in lines 10 to 20 inside a function, and then reference that in the return statement at the bottom. EG: If you called the function phone() your return statement would be return {fieldChanged: phone}.
You are using SuiteScript 1.0 API functions (nlapiGetRecordId() and nlapiLoadRecord()) in a SuiteScript 2.0 script. Under some circumstances these functions may be available so it might work, but even if it does, it certainly isn't best practice.
Loading the record isn't necessary. When you implement an entry point function, the function is passed a context parameter. IE: function fieldChanged(context). That context parameter contains a reference to the current record (context.currentRecord). Work with that instead of attempting to load the record separately.

How to store Body data in post request through jmeter

I am new to jmeter, I am using jmeter to test e-commerce website.
I have manage to script one scenario, which is to add a product in basket and test the response time.
Now, I have observed that when i click Add button on UI, their are two requests which are getting POSTED.
for eg: stocks are updated.
As of now, I have copied the BODY from stock and pasted in jmeter sampler, but in future i may change the Sales order and update scenario, hence i want to store this Body data(Stock request which is updated) of this request dynamically, as it will change corresponding to sales order number im providing.
The problem is I am not able to store the BODY data dynamically(Only if i change the sales order here).
I know i can use pre processor in this matter, but could anyone help me with the code to get the BODY data from the request and store dynamically before sending the sample.
Basically I need a solution where I am just updating my sales order number and rest of the things will be taken care dynamically, in my case the POSTING of Body data for updating the STOCK.
Thank you in advance!
See basically, you're talking about Correlation. As I can understand from your concern. You need the data for the product added to the cart. Which needs data from prev request. This can be easily managed by generating two requests. Extracting from first and using that info for the second one. This will not involve any hardcoding and will work for you in an efficient manner.
Something like:
vars.put('bodyData', sampler.getQueryString())
should do the trick for you, if you put this code into a JSR223 PreProcessor and add this PreProcessor as a child of the HTTP Request sampler which body you need to store - you will be able to access the request body as ${bodyData} later on where required
In the above example:
vars - stands for JMeterVariables class instance
sampler - is for HTTPSamplerProxy
More information: Top 8 JMeter Java Classes You Should Be Using with Groovy

Jira Scriptrunner - Update a parent's field when modifying the child's field

In Jira, we have a series of subtasks all belonging to a common parent task. For ease of explanation, these subtasks will referred to as such, and the parent task will be referred to as the lesson.
On each subtask, there is a field 'Percent Complete', which is manually updated by the user as progress is made on the subtask.
The lesson will also have a 'Percent Complete' field, which the user cannot manually update. Instead, I would like it to be updated through the execution of a Groovy script when a subtask's 'Percent Complete' field is updated by a user, since the lesson's Percent Complete will be comprised of the weighted sums of the child subtask's Percent Complete field.
I'm a programmer with no experience in Jira customization. The actual logic behind getting the Percent Complete value for the Lesson task is super simple, but I don't know how to 'hook everything up'. So my question is this:
How can I trigger a field in a parent task (the lesson) to be updated to a calculated value when the value of the child (subtask) field is changed?
My original thought was to create a Custom Scripted Field in the subtask, and in the groovy script which is attached, find its parent task (the lesson), and then iterate through all of its subtasks, performing the relevant calculations on the required fields and then writing the result to a custom field belonging to the parent.
Is this the right approach?
A script field is not a good approach for what you try to achieve. A script field gets evaluated and runs its script every time an issue is requested, so it would run far too often for your needs. E.g. it will also run for every issue whenever a jira reindex is performed or whenever a user looks at an issue.
Zeddzull commented with a better approach. In a script listener, you can respond to issue updated events and check which field was updated and only update your parent issue if needed.
More documentation is available here.
If you google a bit you'll also find info about how to check for changed fields or how to update a custom field.
Getting your parent issue is as simple as calling the getParentObject() on your issue instance.

soapUi: possible to send list of parameters to test case

Is it possible to send a list of parameters to a test case / step in soapUI? I want to perform some database validation, and I would like to be able to pass a list of the expected values to the test case and / or step that performs the validation.
I know it's possible to send single parameters ("properties") to a test case, but I don't think that's good enough for this use case. My idea is to write a single "test case" that performs the validation that can be called from other test cases, and they pass in the values they expect to find in the database.
If you can generate the list of Random parameters through Groovy script then the best solution is: Through groovy script set the property field's value and pass this value into request using property transfer. The property field value will change at each and every run of the groovy script.
Now run the request in loop in groovy script.
So we can able to run the one test request multiple times with different parameter values.
We have a similar issue. We need to run multiple XML-files as source files for the sequence of requests. We got about 15 steps in the test, and the only thing that changes is the initial XML.
We solved this by using groovy to set a propperty to a comma seperated list, then pick the first element, remove it from the list, and run the tests. In the end, we return to the "pick first element from list"-step if the propperty is not empty.
This is a goto implementation of a basic loop, and we would prefer to do this differently, but we have not figured out how to (we run soapUI via maven2).
If you are using soapUI Pro, you can create a data source step > request step > dataSource loop step.
dataSource step can take excel, XML, grid as the soure. You need to create a property and select the type of the source.
The next step is running the request.
Then you should create a dataSource loop step. This steps returns to the dataSource until running all the request.
Please check soapui documentation
if you are not using soap Pro version, creating a groovy script is the solution as described with the previous answer.

How? SOAPUI and Groovy - send different SOAP message (with property from file) each time?

I'm trying to use SOAPUI (4.0) to do load testing, and I want to have each SOAP request be different, with some attribute values and element values in the requests being populated from (for example) a text file.
The SOAP message is going to be the same for each request, except for the several attribute values and element values.
The SOAP message includes an unsigned SAML assertion, and that has some attributes that need potentially be different for each SOAP request. Among these attributes there's one called "IssueInstant" which is basically a date/timestamp string, and an "Id" attribute, which is a unique string per request.
Ideally, I'd like to be able to populate that "Id" attribute value from the text file.
I've been able to populate the IssueInstant automatically in SOAPUI, by including a small piece of Groovy code, to get the current date/time, re-format it, then store that in a property. This Groovy code is in the startup script in the SOAPUI testcase.
In the body of the SOAP message, I have a Subject element that I want to have populated from the text file.
After the IssueInstant, Id, and Subject are populated, I want SOAPUI to send the request.
So, for example, say the text file has:
id0001,cn=foo1,dc=whatever,dc=com
id0002,cn=foo2,dc=whatever,dc=com
id0003,cn=foo3,dc=whatever,dc=com
Then, when I run the SOAPUI load test, I'd like the first request to have Id=id0001 and subject cn=foo1,dc=whatever,dc=com, the second request to have Id=id0002 and subject cn=foo2,dc=whatever,dc=com, and the third request to have Id=id0003 and subject cn=foo3,dc=whatever,dc=com, and then the load test loops back through those 3 sets of values until it ends.
The thing that I'm having a hard time understanding is how to step through the file in the Groovy code and how the Groovy code is suppose to know which line in the text file is the next line from which to build the properties?
I hope that this explanation of what I'm looking for is clear enough. If not, please let me know, and I hope that someone can help.
In soapUI Pro there exist so called DataSource and DataSource Loop test steps. They are used for looping through a set of test data. For example a text file. If you have the ability to use soapUI Pro, I recommend you to have a look at this: http://soapui.org/Data-Driven-Testing/functional-tests.html
Otherwise you have to load the file via groovy.
how to step through the file in the Groovy code
I'm sure you'll find some code snippets via Google.
how the Groovy code is suppose to know which line in the text file is the next line from which to build the properties
Create a test case property with initial value 1. Always after reading a line increment the value by 1. By reading this property in your groovy code you always know which line to read.

Resources