Sahi Pro - Controller
abstract
The Sahi Pro Controller allows you to interact with Sahi and easily experiment and debug on the browser.
Record Tab
Identify Elements
To identify an element, press the CTRL key and hover over any elementAccessor:
shows the Sahi accessor for that elementAlternatives:
shows all alternative accessors for that elementValue:
shows the value of the current element. Mostly this is the input text or the visible text.Prefix:
Populates the prefix as needed when working with popup windows and multiple domains.
Eg. on a popup window, this may be populated with_popup("New Window")
Action Buttons
These buttons perform various actions on the element and also show the generated script in the "Evaluate Expression" box.These are used to quickly work with elements during debugging/script generation.
Click
clicks on the identified element. Invokes the_click
API.Hilight
highlights the identified element (shows a red 1 pixel border briefly). Invokes the_highlight
API.Set
sets the value in "Value:" field on the identified element. Invokes the_setValue
API.Hover
does a mouse over on the element. Invokes the_mouseOver
API.List Properties
lists all the properties of the element (name value pairs) in the Evaluate Expression results box.Other Actions
lists actions like Double Click, Right Click etc.
Assertions
Assertions are used to verify that the behaviour of the system is as expected.To add assertions using Sahi,
- CTRL-Hover on the element to identify it and then click on
Assert
button - A few possible assertions for that element will be populated in the
Evaluate Expression
box - Click on "Test->" to test the assertions.
Evaluate Expression
Evaluate Expression box is used to evaluate snippets of Sahi code. It helps while identifying elements or while debugging.Put a valid Sahi expression in the Evaluate Expression box and click on "Test->". The result will be seen in the bottom box.
While recording, clicking on
Append to Script
will append the steps to the currently recording script.Selecting some text and pressing "Test->" will only evaluate the selected text.
Similarly Click and Highlight can also be used on selected text or on the full contents of the Evaluate Expression box.
Use . to get attributes
Adding a dot (.
) after the accessor in the accessor field, shows all the properties of the accessor.Further typing narrows down the list of properties.
Clicking on an option (say, disabled) or typing
.disabled
directly in the accessor field and pressing Enter
will populate the value in the "Value:" box. (In this case, .disabled is false)
Clicking on
Assert
will create an assertion for just that property.Up and Down arrows
Up arrow near the Accessor field helps identify the parent element. The Down arrow goes back to the previously identified child element.
Anchor button
Suppose we need to identify the third textbox in the UI below.If we hover over the third textbox, it is identified as _textbox("q[2]")
Instead, we first CTRL-Hover over Python Cookbook; the accessor field shows:
Then we click the Anchor button:
Now if we CTRL-Hover the textbox, we see the Accessor now resolves the textbox in relation with Python Cookbook.
Directly copy the Accessor to Evaluate Expression
You can directly copy the accessor to the Evaluate Expression box by clicking on this button.- Select the text range you want to replace in the Evaluate Expression.
- Click on the copy to Evaluate Expression button:
- The Evaluate Expression now looks like this:
Smart Dropdown for Evaluate Expression
Sometimes, you may want to use a Sahi API on only a part of the expression in the Evaluate Expression box.- Select the part you want to test.
- Click on the dropdown, as shown in the figure.
- Select the API you want to use.
- As you can see in the lower box of Evaluate Expression, the API has been used and shown over there.
APIs List Box
Suppose you want to access an API, but are not sure about the parameters required in it. You can use the APIs List box in such a case.- Start typing the API you would like to use.
- As you start typing the API, a dropdown would appear. Select the API and press the Return Key.
- The API, along with its parameters would get appended to the Evaluate Expression box
Retrieve Coordinates of a point
To get the coordinates of an element, you can use the checkbox shown in the figure.When checked, it displays the clientX and clientY of the point on screen where CTRL-Mouseover event takes place.
History of Evaluate Expression
You can use this option to see recent statements used in the Evaluate Expression box.Record a script
-
Select the scripts folder in-use in the 'Script Directory' dropdown as shown in the image below.
-
Set the name of the script in the 'Script Name' field.
Note: if no extension for the script file is provided, ".sah" is taken as the default extension.
-
Click on 'Record' button and perform desired actions on the web page.
-
Click on 'Stop' button to stop recording.
info
The scripts directory can be changed by changing the following in
sahi_pro/userdata/config/userdata.properties
:#Relative paths are relative to userdata dir. Separate directories with semi-colon
scripts.dir=scripts;D:\my_custom_folder\
Record with Accessor Repository
-
If you want to use an Accessor Repository file while recording, you need to check the "Enable Accessor Repository" checkbox.
-
On selecting the checkbox, another text field will appear where you need to specify the relative or absolute path to the Accessor Repository file.
-
Now if you press the 'Record' button, Sahi will record using Accessor Repository.
-
Once a Accessor Repository file is chosen, an element will always be identified first by its AR entry, even when not in recording mode. This prevents the same element from being identified in multiple ways in different scripts.
-
When elements have been smartly identified using Relational APIs like _near or _under once, newer recordings on those pages will simply use the AR entry, so other users do not need to worry about doing it again or wrongfully using a different identification mechanism.
-
There is also provision to modify existing AR entries.
dangerAccesor repository keys must always be in the format $_ALL_IN_CAPS. If this is not followed, the scripts will still work fine, but the values will not come up properly in Script Editor's context panel.
Record Documentation
Sahi can store screen shots along with recorded steps to act as simple documentation.To record in documentation mode, check the "Enable Screenshot. Used for Documentation" checkbox before clicking "Record".
Read more on Sahi as a Documentation Tool
Playback Tab
With page refresh
If not already open, open the Sahi Controller (ALT-DblClick on the page).- Enter the script name
first_script.sah
in the 'File:' field (with the help of the autocompletion feature). - Enter the Start URL as 'http://sahi.co.in/demo/training/'.
For your own scripts, if you had started recording from http://www.google.co.in, use that URL. - Click 'Set'. This will navigate the webpage to the URL mentioned in the Start URL textbox.
- Wait for the page to reload.
- Click 'Play'.
Note that the Controller can be closed at any time, without disrupting playback.
Without page refresh
On clicking set(number 3 above), the page refreshes before playing back the script. In order to retain some information on the webpage that you need before playing back the script, you can uncheck the checkbox on the left of the label "Start URL". Unchecking the checkbox will run the script on the current page without refreshing it.View logs
On the Controller, go to Playback tab and click on "View Logs" link at the bottom right.It will open a window with the results in HTML.
Click on any script to view specific logs.
Clicking on a line in the logs will drill down to exact line in script.
You can also view the logs at http://localhost:9999/logs
Debug during Playback
To perform debugging on the script, you can perform various operations like Pause, Play, Stop and Step on the script. 'Pause' enables you to pause the execution of the script. 'Step' allows you to execute the script step by step.Play Scripts from a URL
Alternatively, you can also playback a script from a URL.- Click on the link "from url" as shown in the figure
- Provide the necessary Script URL and Start URL.