Back to FAQs

Can I include a script in another script?

Lots of people have asked for a way to create a library of scripts (or snippets) to do common things like logging in, logging out, performing a search, and so on. The concept of code reuse needs no introduction, and is generally a good idea, and it’s the same with test scripts.

You can include one script in another with Include Script steps.

There’s actually nothing special about a script that’s meant to be called from another script. It’s just an ordinary script. Whether you created it with the purpose of running as the primary script, or as a reusable section to be included in another, it’s just a script.

Some things to be aware of when including one script in another are:

  • The scripts have to be of the same type (both Protocol Bot or both Browser Bot, not mix-and-match).
  • The scripts must be in the same project.
  • Circular includes are silently ignored (A can include B, but B can’t then include A).
  • Only the steps are included, so if the included script has any dataset variable mappings they won’t carry over. However, variables from the outer script do carry over to the inner script.

Use your own judgment when deciding how granular to make your scripts. Generally, if you find that the same series of steps occurs again and again in your scripts, it’s a good idea to pull those steps out into a reusable script.