Best Practice for Selecting User in ATF Test Step

Sachin G K1
Kilo Sage

Hi All,

I need to set the Business Owner field, which references the User [sys_user] table. Currently, I'm selecting a real user from the system, but there's a concern that this user may be deactivated or removed in the future, causing the test to fail.

What is the best practice to handle this? Should I create a dedicated "ATF User" to be used in such cases for consistency and reliability, or is there a better approach?

I would prefer not to use the Create User test step, as I need to populate multiple user reference fields, and I'm configuring ATF for multiple test cases. Creating 3–4 users in a single ATF test and repeating the same setup in other tests doesn’t seem efficient.

 

SachinGK1_0-1747914880347.png

 

Thanks,
Sachin G K

1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @Sachin G K1 
Creating users using the "Create User" step is the best approach. Even if multiple users need to be created, they will all be rolled back at the end of the test, ensuring no negative impact.

Regards,
Siva

View solution in original post

4 REPLIES 4

J Siva
Tera Sage

Hi @Sachin G K1 
Creating users using the "Create User" step is the best approach. Even if multiple users need to be created, they will all be rolled back at the end of the test, ensuring no negative impact.

Regards,
Siva

Hey Siva, 

I have to create around 60+ATF's in all these atf i have fill those 3users field, so creating 3user using create user step is time consuming and not effective. Is there any other alternative?

Hi @Sachin G K1 

I recommend creating dedicated ATF test user records in the sys_user table and using them in the ATF test steps.

Avoid using actual user records.

neerajsharma27
Tera Contributor

Hello @Sachin G K1 , Like J Siva said, Create User Step is the best approcah.

 

Alternatively, you can create a Run Server Side Script as following which will retrieve an active user everytime, so you need not be worried about user being inactive.

 

and then in the set field values, you can set it.

 

neerajsharma27_0-1747917123848.png

 

 

//Script to return an Active User

(function(outputs, steps, params, stepResult, assertEqual) {
    var userGR = new GlideRecord('sys_user');
    userGR.addActiveQuery();
    userGR.setLimit(1);
   userGR.query();

    if (userGR.next()) {
        var userId = userGR.getUniqueValue();
        stepResult.setOutputMessage("Found active user: " + userGR.getDisplayValue('name'));
        outputs.user_sys_id = userId;
        return true;
    }

})(outputs, steps, params, stepResult, assertEqual);
 

If my answer was helpful, please click the Thumb Icon and mark it as the solution. This way, it can assist others in the future.

Thanks.