Each week, we will pick a feature of Sahi Pro and hope to highlight its capabilities, benefits and tips on how to use it effectively by asking not more than five questions. We begin our Five Questions Series on Sahi Pro by focusing on Controller.
What is Sahi Controller?
Sahi Controller allows you to interact with Sahi and easily experiment and debug on the browser. Using Sahi Controller, one can easily identify elements, record and playback the scripts. One can launch Controller by pressing ALT and double clicking anywhere on the browser. Kick-start your web automation by recording using Sahi Controller and using the scripts as it is or creating functions out of the recorded snippets of code.
What are the capabilities of Sahi Controller?
Sahi Controller has many powerful capabilities spread across four tabs?—?Record, Playback, Clipboard and Info.
Record: This tab has controls to record a script. Recording is as easy as entering a name for the script and clicking on Record button. All the actions performed on the browser will be recorded and displayed in ‘Recorded steps’ tab.
One can identify elements using CTRL + mouseover and the Sahi Accessor for the element is displayed. Other actions like Click, Highlight, Set, Hover can also be performed on this element.
As seen in the image, each button invokes a specific API.
Click: _click API
Hilight: _highlight API
Set: _setValue API
Hover: _mouseOver API
Assert: One can add assertions to verify if the end result is as expected. To add assertions, CTRL+mouseover an element. Click on ‘Assert’ button to view the possible assertions. It will be displayed in the ‘Evaluate Expression’ tab. Once tested, the assert statements can be appended to the main script.
Evaluate Expression: This can be used to evaluate snippets of Sahi code. Clicking on Test will evaluate the content and display the result (true/false/undefined) in the box below.
Smart dropdown for Evaluate Expression: If one wants to use Sahi API on only a part of the expression in the Evaluate Expression box, select the text and choose an action from the dropdown. This would in turn trigger an API and the results will be displayed in the box below. In this case, the ‘Is Visible’ option to trigger the API ‘_isVisible’ on the element ‘_textbox(“total”)’ is highlighted.
Playback: Using this tab, one can playback the scripts which are already recorded. Providing a Start URL and checking the checkbox will ensure that the script runs by first navigating to the URL mentioned. If the checkbox is not checked, the script will be executed on the current page without refreshing it.
Clicking on each of the links will open the respective window. For ex: Clicking on Logs will display the logs for all the scripts run so far. Clicking on a specific script on that page would display the specific logs.
Clipboard: This tab can be used to store small pieces of information.
Info: This tab shows the basic information of Sahi Controller, mode, browser, operating system and Java.
How are the elements on a web page identified?
Any element on the webpage can be identified by pressing CTRL and mouseover the element. The best Sahi accessor for the element is displayed by default in the Accessor field. One has the option to choose an alternative from the ‘Alternatives’ dropdown. Value shows the value of the current element. Prefix populates the prefix as needed when working with popup windows and multiple domains.
Tell us more about the Relational API and anchoring an element.
Sometimes, an element changes its position/name due to code changes and the whole script fails as the tool is not able to identify the element. To get rid of this issue, a very powerful option is Relational API and anchoring an element.
Let us take the following example where we have to identify the quantity field against “Ruby for Rails”.
If we identify the field in isolation, the Sahi Accessor reads:
What if three more book titles are added before Ruby for Rails. The Accessor for the field against Ruby for Rails also changes. To avoid this situation, let us anchor the label ‘Ruby for Rails’ first and then identify the field against it.
How does recording with ‘Enable Accessor Repository’ on help?
If ‘Enable Accessor Repository’ checkbox is checked, Accessor Repository file text field appears. Once the user clicks on ‘Record’ button, Sahi will record using Accessor Repository. In the ‘Accessor Repository File’ text field, we mention the relative or absolute path to the Accessor Repository file.
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.
One important thing to note with Accessor Repository keys is that they 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.
Any other questions in your mind?
Feel free to comment or ask your question(s) and we will get back to you.