If you’ve followed the previous parts of this introductory guide, you’ve been able to create, deploy and execute a keyword in step. Let’s now look at how you can leverage the platform to create a large scale scenario for functional or performance oriented purposes.
Plans are a separate entity making use of Keywords. step provides a Plan editor which allows users to design automation scenarios in full isolation from Keyword implementations. Plans provide a wide array of pre-existing logical controllers usually referred to as Controls, which are a type of Artefact. Other artefacts can be used to build plans, one of the most important type being Keyword calls.
Let’s create a new plan: Go to the Plans tab of step’s top menu -> New Plan button -> Enter My First Plan in the Name field -> Save and Edit button.
Let’s create a simple plan which will iterate through an array of JSON values and display them one by one. Add the ForEach artefact from the Controls library in the right hand pane of the editor.
Notice that a plan structure is based on a tree. The order and relationship between the different nodes of the tree plays an important role so make sure to understand how they’re supposed to interact before adding them to your plan. Documentation regarding each Control is provided under User guide.
The ForEach control takes a source of data as a primary input. In this example, we will use the Source type JSON String and pass a simple JSON document which can be iterated over. The document must represent of table of values with headers first, and then rows. Let’s use the following string as an example:
Your artefact’s configuration should now look like this:
Now let’s use the Echo artefact along with some dynamic groovy code to display the contents of our JSON table. Add an Echo control as a child of the ForEach node in your tree, toggle its groovy button (lightning icon) and set the following code in its input box:
"Page "+row.pagename+" can be accessed using the following url: "+row.url
The Groovy language is used throughout step to resolve variables and perform simple technical operations. It is a convenient and flexible way to add dynamic behavior to a plan.
Your Echo node should now look like this:
And if you execute the plan (Play icon -> Environment TEST -> Play icon again), you should see the following result:
Note: make sure that you’ve checked the Groovy toggle button in your Echo artefact’s configuration, otherwise, the dynamic variables will be interpreted as static strings.
In the guide My First Keyword we’ve hinted at the fact that Keywords can be used to receive and return data. Let’s see how we can leverage this to connect our keyword with our newly created data source.
Let’s say we want our chrome driver to iterate over the urls provided by our data source. We’ll first have to change the code of our keyword slightly in order to look for the url attribute. So let’s make the following change to our ChromeKeywords class:
Notice that we’ve replaced the hard coded url with an access to the mother class’ input object via a key representing the input’s name and replaced our selenium instruction to return a description field from the webpage as an output of the keyword.
We will also make a small change to our JUnit test from the class ChromeKeywordsTest so that it can find the necessary input and display the description output when executing the keyword locally:
Let’s now save our source files, rebuild (Run As -> Goal: package -> *Run) and redeploy our keyword by re-uploading the jar file into the configuration screen of our keyword (Keywords menu entry -> Configure Keyword by clicking on the Wrench icon -> drag & drop your fresh uber jar into the Script field).
A popup will be displayed asking you wether you’re wanting to update the existing resource, which will override all existing references throughout all keywords potentially using the same file, or bind the new file as a new, distinct resource which will only apply to this keyword.
Let’s now return to our plan (Plans menu entry -> Edit Plan by clicking on the Pencil icon), delete the Echo artefact and add a Keyword call from the Keywords sub-tab, in the right-hand pane of the Plan editor. After rebinding the input variable properly, your plan should now look like this:
One of the nice things about using Outputs in step is that we can decouple the validation of certain property or fact about your application outside of the automation script. Let’s go back to our plan and add an Assert control to make sure that all descriptions start with the word “We”:
If we run this plan, the description outputs will be successfully matched against the Assert’s pattern and both keyword executions will succeed.
If we now add another Assert to make sure that the word “product” is contained in every description,
as expected, one of these two steps will fail.
We now have a relatively meaningful automation scenario with some amount of validation. However, as you can tell, each time an iteration commences, a new driver instance is started, which is highly inefficient in terms of resource management.
Let’s leverage step’s Session control in order to manage our chrome driver instances more elegantly. First, we’ll modify our keyword code in order to register our chrome driver object into step’s session map. Just like the input and output objects, the session map is made accessible via the parent class (AbstractKeyword).
We’ll also split up our keyword into three to better reflect the different phases of the browser’s lifecycle.
Again, the project will have to be re-packaged and the jar re-uploaded into step. This time however, we will have to create 3 new keywords each sharing the same jar resource in step.
After uploading the new version of your jar file, use the selector to pick the same existing resource for the two other keywords.
Note: it is important that each keyword originating from the same jar be mapped to the same instance of the file as opposed to different copies. If you see multiple resource entries with an identical filename, you should clean up unnecessary entries and make sure afterwards that all keywords are bound to the remaining resource.
Your selection screen should look like this:
If it is not the case, go to the right-hand drop-down list of the top menu, click the Resources entry, and delete unnecessary entries, then repeat the configuration process:
Once all three of your keywords are created (as illustrated in the following screenshot),
go back to your plan, add a session object and reorganize your new keywords as follows:
Note: don’t forget to pass the “url” input to the navigate keyword call.
If you run the plan now, you’ll find that your chrome instances properly shut down after execution.
Finally, let’s wrap our navigate call into a For loop artefact with 10 iterations:
You’ll now see that each browser instance will execute the navigate keyword 10 times before shutting down, making more efficient use of the browser instances.
Check out the next section to see how executions can be scaled across an agent grid.