ATF background script

LekhrajD6645142
Mega Contributor

Hi Team, I am trying to run ATF with an background script but I am unable to do so with Suites and Tests, so does anyone of you have come across this type requirement? Eventually I need to run ATF with BR.

1 ACCEPTED SOLUTION

Nayan ArchX
Tera Guru

Hi,

 

https://www.servicenow.com/docs/r/application-development/automated-test-framework-atf/run-scheduled...

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks

Nayan Patel

IT ServiceNow Consult, ServiceNow ArchX

If my response has resolved your query, please mark it Helpful by giving it a thumbs up and Accept the Solution

 

 

View solution in original post

5 REPLIES 5

Nayan ArchX
Tera Guru

Hi,

 

https://www.servicenow.com/docs/r/application-development/automated-test-framework-atf/run-scheduled...

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks

Nayan Patel

IT ServiceNow Consult, ServiceNow ArchX

If my response has resolved your query, please mark it Helpful by giving it a thumbs up and Accept the Solution

 

 

Ankur Bawiskar
Tera Patron

@LekhrajD6645142 

why to run ATF with background script?

Not a valid business requirement.

ATF are meant to be scheduled if your customer wants or users can run them manually

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for the suggestion

VaishnaviK3009
Tera Guru

Hi @LekhrajD6645142 !!

 

You cannot directly run ATF tests with a background script because ATF runs in its own test context and does not execute scripts in the global Background Scripts module for security and isolation reasons.

 

Here’s how you can handle this requirement:

  1. Test Business Rules with ATF directly:

    • Instead of running a background script, create ATF steps that simulate the record changes that trigger your Business Rule.

    • Example:

      • If your BR runs on insert/update, create an ATF test step to insert or update a record in the target table.

      • Then use Assertions to verify the outcome of the BR (e.g., field values, related records created, notifications sent).

  2. Use ATF “Run Script” steps carefully:

    • ATF allows you to run small Server-side scripts as part of a test, but these scripts must operate within the ATF test record context, not global scripts.

    • You can replicate your BR logic partially here if needed for testing.

  3. Workarounds if you need complex logic:

    • Create a Test Utility Script Include containing the logic you want to test.

    • Call this from ATF test steps instead of using a background script.

    • This keeps your logic reusable and ATF-compatible.

Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.

Regards,
Vaishnavi
Associate Technical Consultant