ATF: Parameterized tests - is it possible to change assert type based on parameter values?

Ana41
Tera Contributor

Hello, all! I have a question regarding parameterized testing in ATF and I have not been able to find this info, so I am hoping someone out there can help.

I need to build some tests to validate the access of different roles to records in a custom table. I'll give you a simple example:

Test A - Create a new record in table XYZ

  • role '123' is able to create new records
  • role '456' is not able to create new records

I created Test A as a parameterized test, with one parameter - the user role. I then created 2 data sets: one for role '123' and another one for role '456'. My problem is that it does not seem possible to use the same test to assert the 2 different scenarios:

  • Test A step 1: create and impersonate user with the role that is in the parameter value
  • Test A step 2: assert that the record was created --> the record is only created for role '123'; when the test runs for the second parameter, role '456', it fails

Is there some way to change the assert type so that it validates that the record was created for role '123', but then validates that it was NOT created for role '456'? 

My solution for now is to duplicate these tests so each one has a different assert, but this seems cumbersome and generates a lot of repeated steps and extra work (even though I am using templates, it feels like there should be a better way to accomplish this).

Thanks in advance 🙂

 

6 REPLIES 6

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Hi Ana

I see the challenge with low code solution. Will you be able to use the step 'Run server side script' as Step 2? You can use the query like below:

var grXyz = new GlideRecordSecure('XYZ');
grXyz.setValue('column_1', 'someValue');
var newRecordId = grXyz.insert(); //This returns sysID if insert is successful, null otherwise
var testAssertion = {
           name: "Validate record insertion",
           shouldbe: params.expected_insert, //expected_isnert is the boolean parameter
           value: JSUtil.notNil(newRecordId), 
     };
     assertEqual(testAssertion); // throws Error, logs message to test step output

--
Best Regards 
Ankush 

P.S. Please mark helpful/correct as appropriate to help the fellow community member in identifying the relevant answers.

 

Shan C
Mega Guru

@Ankush Agrawal Relevant question. Appreciate any inputs.

 

I am using custom UI Step config, and is it possible to assign a value to an output variable or a shared/exclusive parameter from within the executeStep script?

Hi Shan

Thanks for reaching out. UnfortunatelyerviceNow does not allow the customisation or new creation of the Custom UI step due to the maintenance and stability aspect of them. 

Thanks.

I am able to create new custom UI step config(using coping an existing Custom UI Step Config), and been using for some days since Paris. I understand, lot of limitations are there as this is just evolving, and would like to know if the output variables value assignment is possible.