To illustrate learning an object, we return to the TwoDialogs sample.
First, let's learn the OK button using recording. We have done this before in the TwoDialogs sample.
1.Run TwoDialogs sample Windows application. By default this will be located in C:\Program Files\Inflectra\Rapise\Samples\TwoDialogs\TwoDialogs.exe
2.Start Rapise and create a new test, choose the Basic - Standard Scripting Mode, and call it TwoDialogsRecording.
3.Press the Record/Learn button in the Test ribbon of Rapise.
4.When the "Select an Application to Record" dialog is displayed, choose the TwoDialogs.exe application and in the library list, select only the top library on the list - "Auto." Press the Select button.
5.In the TwoDialogs application, use the mouse to press the OK button. Dismiss the alert message box complaining about the empty name.
6.Notice that two things will happen. Firstly, the OK button will be surrounded with a red marker, indicating that the OK button has been learned. Secondly, the action of clicking the OK button is recorded in the Recording Activity dialog. That recording has a single entry.:
7.Press the Finish button (or press Ctrl+3) to end the recording.
8.Rapise will return to be the foreground application, and it will have selected the TwoDialogsRecording.js (or whatever name you gave the test when you created it).
9.Notice that there is a single line or script that has been added to the script file:
This line of script has two interesting parts.
The "SeS('OK') is the identity (not the locator or location) of the OK button. This is the object that was learned during recording.
The "DoAction()" is the instruction to the running script to take the action associated with a button. A normal button has only a single possible action - to be pressed.
The Record/Learn process has taken both steps for you, and joined them together.
Now, let's use (normal) object learning to learn the same OK button and to call a method for the object.
1.Run TwoDialogs sample application. By default this will be located in C:\Program Files\Inflectra\Rapise\Samples\TwoDialogs\TwoDialogs.exe
2.Start Rapise, create a new test, choose the Basic - Standard Scripting Mode and call it TwoDialogsLearn.
3.Press the Record/Learn button in the toolbar.
4.When the "Select an Application to Record" dialog is displayed, choose the TwoDialogs.exe application. Leave the library selection in its default state - we will not be using it this time. Press Select. Wait for the Recording Activity dialog to appear in the lower-right corner of the screen.
5.Hover the mouse over the OK button of the TwoDialogs AUT but do not press the button.
6.With the mouse positioned over the OK button, press Ctrl+2 ( the "Learn" command). You will see the OK button surrounded with a red highlight. You will also see that the Recording Activity dialog has been updated with a Learn event.
7.Press the Finish button or Ctrl+3 to end the recording session. You will now see that Rapise has "learned" about the OK button, and the Object Tree in the upper left-hand pane of the Rapise has a new entry called "OK" (shown here expanded). The list of items contained under the OK button entry in the Object Tree is the set of methods and properties available for the OK object.
8. While we are looking at this OK object, let's make a few observations about it. These observations will be useful for your later dealings with Rapise and will make the script more informational and relevant as you delve into Rapise. First, look down at the Properties box that appears under the Object Tree in the bottom left corner of the Rapise screen. The screenshot below has some of the tree nodes expanded.
First, notice that the OK button has four (4) "locators" defined. When you have Rapise "learn" an object. it must collect data about that object so that it can relocate it even if the application has moved on the screen, and even if the application is in a different state of execution. In order to accomplish this, Rapise looks for all useful ways to uniquely identify the object. As bad, or perhaps worse, than not being able to find an object would be to find the wrong object on the AUT. Every time Rapise is required to locate this object, it will first try to use the first locator. If it fails to positively and uniquely match with that locator, it will try the second, and so on. Rapise will not give up and declare failure until it has failed to identify with all available locators.
Second, notice the ID entry in the Object section of the pane. This is the name of the object from Rapise's perspective. All Rapise names are available through the SeS() function call. Therefore, if we want to refer to the "OK" object, we will use SeS("OK") to refer to it. Once we have correctly identified the object, all valid methods and properties can be accessed by using that object as the basis.
9. In the automated (recorded) section above, you saw that when you pressed the OK button on the dialog, Rapise recorded a function like this:
This time, you will use the established name of the OK button object, but do something a little more interesting than its default action to demonstrate how to use Rapise.
10. Move the cursor into the editor part of the Rapise and make sure you are editing the file called TwoDialogsLearn.js. At the moment, this file still looks something like this:
//########## Script Steps ##############
Between the open and close brace, add the following command:
Hit the Play button and watch what happens.
The click will register as a command to the object and it will perform the action on the object.
While we have the context of this situation, let's complicate it just a little more to illustrate the intricacy as well as the flexibility of Rapise and SeS.
There is a method whose names looks interesting: DoLButtonDown().
If we were to invoke DoLButtonDown() on the "OK" object, we would expect this would be the same as DoClick().
However, go back to the AUT for a moment. Using the mouse, press the left mouse button over the OK button but don't take your finger off the left mouse button.
What happens is that the button takes its pressed state in appearance, but the button is not clicked.
The reason for this is that the DoClick() (or DoAction()) events cause the mouse button top be clicked as well as released.
Therefore, we would need to have a pair of events:
in order to make the "click" happen.
Try this in the test script you have created by adding those two lines of code in place of the DoClick() line.
It doesn't work!
Let's play a little with this problem.
When you press the Play button, leave the mouse alone. Just press the left mouse button on the Rapise Play button and take your hand away from the mouse.
The script does not press the OK button in the TwoDialogs AUT.
Now, press the Play button on the Rapise and quickly move the mouse to hover over the OK button in the TwoDialogs AUT.
Now it works!
What's going on here is that the DoLButtonDown() and DoLButtonUp() methods are pressing the mouse irrespective of where the mouse cursor is positioned.
The other functions, DoClick and DoAction are methods that are applied to the button and so they are applied to the button.
Before we can expect DoLButtonDown() and DoLButtonUp() methods to work, we have to first the mouse cursor to the button.
will accomplish that.
Notice that Rapise will actually move the mouse to the coordinates (25, 15) within the OK button. Also notice that if you move the mouse while the test is playing, you will make the test fail.
As a last experiment in this arena, try moving the mouse outside the boundaries of the OK button object before calling the DoLButtonDown() function.
Once again, the script will fail.