2 Steps has been designed from the ground up to be as easy to use as possible. Nonetheless solving some problems unavoidably involves a little bit more work. One example is a test which requires the current date or time to be entered into a field or verify it on the screen. In this video, I'm going to be showing you how we go about achieving that in 2 Steps, using a combination of custom scripts variables and define with OCR command. I'm not going to go into too much depth here about variables because there's another video in this training series, which goes into them. So you may want to view that video first, if you haven't already to keep things simple, the actual test I'm going to build is not going to be particularly realistic. I'm simply going to enter today's date into a Google search input, and then confirm that the date is in the expected place on the screen. As I say, not very realistic, but it should suffice to demonstrate the techniques involved. So, first of all, I've created this test, which I've just called today's date, and it's a Chrome test with the web, address set to google.com. And the first thing I'm going to do is click in the search field.
Now I want to enter today's date, but how do I do that? Obviously I could just type it in, but when this test runs automatically later, it needs to enter the date that the test is being run out obviously not the date when I happened to create the test. So I need something that's going to generate that date for me. And that's where custom scripts come in. So custom scripts are small programs which are installed on the 2 Steps server, which can do pretty much anything you want and which can output a value to a variable. I've created an algorithm which outputs today's date in any format I want. To run it, I right click to bring up the advanced command menu and I select run script. Now I need to choose the script. The available options here are going to depend on what scripts you have registered on your 2 Steps server.
You can see, I have a number of different ones here. I'm going to select current date time v2.2, and now I have to complete the inputs and outputs for the script. In this case, I need to provide the date and time format as an input. The description here provides a link to the format options in case I need to refer to that. I'm going to ask for the date in day/month/year format slash-separated, and also have a field for the time. And I want to output it to a variable, which I'm just going to call today. And then I click, okay. And the script runs and the variable today should now hold the format of data and time. So I want to type that value now into the search field. So I right click and select the type command. Now I have to input something here, even though it's actually going to be replaced by the variable. So I'm selecting the variable, but I'm also going to just type in some filler ticks there. And so now you can see that 2 Steps has entered the current date and time into the input field. So the last step is that I want to verify that text on the screen. I can't use a normal 'wait for image' command here because the date is going to be changing all the time. So I'm going to have to use OCR to verify that the text is on screen at the expected place. So to do that, I'm going to click on the magnifying glass image. And then I select the 'find with OCR command'.
You'll see that in addition to the normal blue square, which indicates the image of the 2 Steps is looking for there's also this green rectangle showing the region where I'd expect the text to be found. Now I need to resize that and move it until it covers the area that I expect texts to be. And you'll see the 2 Steps extracts, the actual texts that is found there, but I need to specify the variable. I'd say that it needs to look for the contents of the variable today at this location. And so you can see that that has succeeded. So the last thing I need to do is to just reset the test and run it again, to make sure that it works and you can see for yourself that it enters the actual time rather than the time that I had before. So that's it. Even though these are advanced techniques, it's all pretty straightforward and can be done in just four steps.