automated test framework - Server-side script to iterate through records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 05:28 PM
Hi Team,
I've posted about this on one of Dave Slusher's blog posts, but I thought I'd pose it as a question here to see if anyone has any thoughts.
I would like to run automated tests using the ATF to create large bulk sets of records but with slightly different values for each record. I believe I should be able to use the Server-side scripting part of ATF to achieve this, but I'm struggling to understand the syntax.
The structure for Test Steps should be something like this:
1. Impersonate a user
2. Launch a form
3. Select standard values
4. Perform a server-side script to see if previous tests in the suite have output a "u_task_subcategory" reference value.
- IF NO: perform a gliderecord query to grab the first record in an ordered set and "Output" for the next test step
- IF YES: perform a gliderecord query to grab the next record in an ordered set based on the previous value and "Output" for the next test step
5. Populate the u_task_subcategory referencee value with the output of step 4.
6. Submit record
7. check for the presence of a sla_contract record where the parent record is the current record.
8. Output the u_task_subcategory value in preparation to pass it to the next iteration of this test (template? not sure how best to do this).
Am I on the right track with this? has anyone got any good code examples for how this might be done via the server side script Test Step config?
Would appreciate any help here.
Cheers,
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 07:02 AM
I attempted to reference the step sys_id from another test inside of a test suite but was unsuccessful so I don't know how best to accomplish step 4.
I don't know how "correct" it would be to do all of your steps inside of a server-side script, but I believe it is possible. The problem with doing it this way is that it would create actual records, and not something rolled back by ATF.
One option you can try, which will have roll-back, is to create a template for Impersonate, Open a New Form, Set Field Values, and Submit a Form. You can then repeat this template throughout your test or test suite.
You would have to manually go through each value for u_task_subcategory.
The drawbacks to this approach are:
1) it's not easily maintained. As items are added to or removed from u_task_subcategory your test will have to be updated as well.
2) the test becomes very large.
3) ensuring the proper step references (document_ids) are maintained.
It would be a nice enhancement if we could reference steps from previously run tests within a given test suite. This would simply mean that the test suite itself does the rollback rather than each individual test.
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 04:01 PM
Hey Chris,
Thanks for your reply! It's good to hear from people who are exploring the new functionality.
I've made some progress from my first attempt, and I'm on the cusp of trying to pass step output values between tests - I don't know how successful I'll be yet, but I hope to have tested by the end of the week.
I'm hoping that I can use a template like you suggested where one of the final steps is a server-side script to create an output value for the current u_task_subcategory reference, and I'm hoping that the NEXT template that executes can read that reference value that's been output by my script (hoping that outputs are sustained outside the test even if the record has been rolled back!) , then the template can use that value to do a gliderecord query to find the next record in the table and run the same test, then output again etc etc.
I think the flaw in this will be that the templates will only exist as finite tests in a suite - I don't think I'll be able to dynamically "loop" tests in a suite so that they repeat for the count of records in u_task_subcategory. I don't think ATF will be that sophisticated.
For the record, here's my hacky code that is able to query u_task_subcategory and return the first value:
(function executeStep(inputs, outputs, stepResult) {
var query = new GlideRecord('u_task_subcategory');
query.orderBy('sys_id');
query.query();
if (!query.next()) {
stepResult.setOutputMessage(gs.getMessage("No records matching query:\n{0}"));
stepResult.setFailed();
} else {
stepResult.setSuccess();
//outputs.u_table = u_task_subcategory;
outputs.u_first_record = query.getUniqueValue();
stepResult.setOutputMessage(gs.getMessage("Found {0} {1} records matching query:\n{2}",
[query.getRowCount(),
query]));
}
}(inputs, outputs, stepResult));
My next job will be to write another script that grabs the current reference and selects the next record in the ordered list - my glidequery knowledge is a bit rusty, so If anyone is gracious enough to help me with constructing that query, it'd save me some time
Either way, thanks for reading and replying Chris!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2017 01:10 PM
Let me know if you get the 'outputs.u_first_record' thing working...
What I've run into is that I can only set the available variable, record_id, with one value.
I wanted it to pass an object, and it appeared that it was successful based on the stringify of the record_id in the previous step, but I could not dot-walk from record_id to anything else. It simply passed a sys_id of a record, rather than the whole object.
Your syntax is a bit off as well. What I've been able to use is 'step.outputs.record_id ='.
In your next step there is nothing to dot-walk to...so if you want to pass a sys_id, then in the next step use:
steps('previous step sys_id').record_id
The same holds if you want to pass the display value of an Incident record, a string, any other single variable item.
Happy testing

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2018 06:21 AM
I hope/think this is the thread I need. I'm trying to open a record producer and submit a record for each of the available values in the underlying table.
- Open Record Producer
- Query Foo with Server Side script
- while foo.next
- output.recordID = foo.sys_id
- Set variable values on open Record Producer in Step 1 via
-
{{step['533e13bc4f12df40d52baf7d0210c7bc'] record_id}}
It's not working. I won't believe that you're unable to
- Open a Form
- Iterate through all possible values for a given field
- Submit form after setting each value
So if I have 10 products then one test would run 10x with 10 diff values. And if I add/delete a product it would still work because in that 2nd step I'm always requerying the underlying data. This seems elementary right?
I'm new to SN and I guess we're all new to ATF. So any SN reps want to wade in here and clear this up?
Thanks