Snippets and Templates
Last updated
Last updated
With the addition of step autocomplete, finding the right steps became a simpler task. Over time, however, you may notice that you keep reusing the same steps to achieve certain goals, like querying tables, selecting a value from a list, or responding to an eSignature dialog, etc.
Until recently, you would either type in the same steps again and again, or find a place in another scenario where you used the steps before and copy/paste them. But remembering where you used the steps and finding them may be challenging once you have a large library of scenarios.
Now, there is a better way. We've added the ability to define and insert snippets with commonly used blocks of steps into your scenarios. Since we write a lot of scenarios ourselves, we've also started a shared repository of snippets available to you that we will keep adding to over time.
When adding a new script to your project, you start with a blank slate. Before you could get to the meat of your scenario, you have to enter a few required lines. To help you avoid that, we've added Templates - cousins of Snippets. While Snippets allow you to reuse blocks of steps, Templates provide starting points for an entire script.
Snippets and templates made available by the testgrinder team are immediately accessible to you. To use one of these templates, simply create a new script in your project and then right click anywhere in the script editor. The context menu will appear with the snippets section:
Once you pick a template, it will be immediately inserted into the editor:
Now that's you've got a good starting point for the script, let's talk about snippets. While you use a template as a starting point for a new script, you add snippets as many times to your scenarios as you need. Let's say you get to a point in your script where you know Maximo will present the eSignature dialog. You could either manually enter the steps for going through the dialog, or better yet, insert a snippet that we've provided for you:
After choosing the snippet, it will get inserted below the line with the cursor:
You may need to tweak the snippet to adjust it for your case. For example, here you may want to update the Reason for Change value.
We will continue adding more templates and snippets as time passes, but you may not want to wait for us. Luckily, you can define your own snippets and templates.
You are not limited to only using predefined snippets and templates - you may make your own. You define your snippets in specially formatted testgrinder projects which you then designate as snippet sources.
Start with creating a dedicated project for snippets and/or templates. Names of project folders and scripts will appear in the choice tree in the editor context menu. The content of scripts will become the actual source of snippets and templates.
To indicate that a script provides a template, insert this comment as its first line:
Here's how the template we used earlier appears in the editor:
Snippets come from the content of the first scenario in the script. Without doing anything special, testgrinder will consider all scenario steps as the snippet. But if you'd like to designate only some of the steps, use these comments as markers:
Here's how the snippet we used earlier is defined:
You may ask why would you want to have extra steps besides the ones that are part of the snippet there? A good reason for these is to establish the test context for the snippet. Note how this script could be run in testgrinder to verify that the snippet works. This allows us to achieve two goals at the same time - provide a snippet and test it too.
To designate a project as your own snippet source, go to the Account page, and select the Snippets tab. Here you can pick which projects will be the snippet (and template) sources. Note that you may also deselect the the sources provided by the testgrinder team if you wish:
Now you have access to both shared snippets and templates and your own:
We hope you find that snippets and templates increase your scenario writing productivity. If you have suggestion for what snippets and/or templates we should add to the shared sources, please let us know.
Besides sharing testgrinder Snippets and testgrinder Templates as snippet sources, we also publish their respective testgrinder projects on GitHub. This enables you not only see how these snippet sources are defined, but also, perhaps, use them as the starting point for defining your own snippet source projects.
You may found out more about them in these help center articles:
testgrinder Templates Projecttestgrinder Snippets Project