Discover how you can build variables into your synthetic monitoring tests with 2 Steps for Splunk. Instead of building multiple individual tests, learn how including variables can deliver great flexibility for your synthetic monitoring tests for web, Windows, Citrix or mobile.
Transcripts available below.
(00:01):
In this video, I'm going to show you how to use variables in 2 Steps tests. Now, this is an advanced technique. So if you aren't already familiar with the basic usage of 2 steps, I suggest checking out the early videos in this series first. Variables allow you to change the text that is used in any command that takes a text-based input, such as 'type' commands and 'wait for text' commands. The easiest way to understand how variables work is by example. So I've got this test here, which searches an online home improvement store catalog website. And I'm going to add if they're able to it to make it more flexible. Let me hover over the steps of the test to show you what it does. So, first of all, I click on the search input. I type the word 'hammer' and we click the search icon and we scroll down to the results. And then we click on the first item in the list. Now I'd like you to take note of something interesting here at step six. You'll notice in the snapshot for this step, that the pointer is some distance below the image I've asked two steps to look for, and this case, the word results that may click on the edit button. So I can show you what's going on here.
(01:14):
You can see the cross has the mark where we want to click is outside the box that shows the image we are looking for this step. That's deliberate because I want 2 Steps to click on the first product in the list, regardless of what it is. If I click directly on the hammer image like this, then the test would fail. As soon as that product wasn't in the first row of items for this search term. Okay. So let me cancel out of that edit. And now the test goes on to exercise some of the functionality of the shopping cart, which I won't go into now because it's not relevant. Okay. So let's imagine I want this test search is for multiple products. So I don't want to test that I can order not just hammers, but also screwdrivers and nails, for example. One way I could do that would be to copy this whole test and change the search text here at step two for each of those individual tests.
(02:06):
But that's going to get hard to maintain because if the site changes and a need to modify the test, I'm going to need to change three different tests instead of just the one and that's where variables come in. Instead of copying the whole test, I can create a variable for the product which I can set at runtime. In order to do that, I go to the spanner icon here, click on that, which opens the variables editor. Now to create a variable, I have to give it a name, and I'll call it a product. And then I can assign it to a step by clicking on the dropdown here, which shows me all of the possible steps where I could use the variable. I'm going to choose the top one, replace text of step two. Now that appears under usage. Note that I could assign it to more than one step if I wanted to, but in this case I don't.
(02:58):
So I'll just click Okay. Note that I can achieve the same thing by editing the step and selecting use variable here and typing the name of the variable... Either way is fine. The variables editor is useful though because it gives you a nice overview of where and how all the variables in the test are being used. You can say, now that in step two the word product in square brackets has been substituted for the word hammer and the color has been changed to orange. That indicates a variable substitution at this step. Now the next step is to create some schedules where I can assign values to my new variable. The idea here is that I'm going to create one schedule where the product variable is set to hammer. Another word, it's set to screwdriver. And another word it's set to nail. So I click on the schedules icon.
(03:48):
Then I create a new schedule. I click on the advanced options and here I can assign a value to the product variable. I'm also going to change the description because I wanted to make it clear exactly what this schedule is doing. Now I can repeat the same thing...then click save. And now we have the same test testing, three different products. Now you do need to be careful here to construct your test in such a way that it will work with the different values that the variable will take. That's why I showed you step six earlier, I've constructed each step so they will work regardless of the specific product that's being searched. It's a good idea to test that by changing the default value to each of the different values that the variable will take and running the test again, just to make sure. So that's a quick introduction to variables in 2 Steps. I've just scratched the surface here because there are even more powerful and flexible ways to use variables when you combine them with custom scripts. But I'll demonstrate that in another video.