Sahi Controller

abstract The Sahi Controller allows you to interact with Sahi and easily experiment and debug on the browser.

Record Tab

Record tab for Sahi Pro.

Identify Elements

To identify an element, press the CTRL key and hover over any element

Modes available in Sahi Pro for recording or identification:
  1. Browser: This mode is always enabled in Sahi Pro. Uncheck the checkbox for recording or identification in Browser mode only.
  2. Windows: Check the checkbox to enable recording or identification for Windows. Sahi Pro Desktop Add-on should be installed for this.
  3. Java Applet: For recording or identification in Java Applet mode Sahi Pro Desktop Add-on should be installed.
  4. Java Web Start: For recording or identification in Java Web Start mode Sahi Pro Desktop Add-on should be installed.

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.

Assertions

Assertions are used to verify that the behaviour of the system is as expected. To add assertions using Sahi,
  1. CTRL-Hover on the element to identify it and then click on Assert button
  2. A few possible assertions for that element will be populated in the Evaluate Expression box
  3. Select mode for evaluate application of which it identified
  4. Click on "→" 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.
info Note: Selecting some text and pressing "→" will only evaluate the selected text. User may evaluate more than one statement at a time.

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.
  1. Select the text range you want to replace in the Evaluate Expression.
  2. Click on the copy to Evaluate Expression button:
  3. 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.
  1. Select the part you want to test.
  2. Click on the dropdown, as shown in the figure.
  3. Select the API you want to use.
  4. 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.
  1. Start typing the API you would like to use.
  2. As you start typing the API, a dropdown would appear. Select the API and press the Return Key.
  3. 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+SHIFT+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

  1. Select the scripts folder in-use in the 'Script Directory' dropdown as shown in the image below.
  2. 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.
  3. Choose the type of application for recording or identification.
  4. Check the checkbox to enable recording or identification for Windows. Uncheck the checkbox for recording or identification in Browser mode only.
  5. 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

Accessor Repository (AR) is a central place to keep all Acessors (object identifiers). When an element changes, its identifier can be changed in a single place and it will reflect in all scripts. In Sahi, AR is implemented as a simple Sahi script with a _AR.sah suffix. Accessors are stored in simple variables.
  1. If you want to use an Accessor Repository file while recording, you need to check the "Enable Accessor Repository" checkbox.
  2. On selecting the checkbox, another text field will appear where you need to specify the relative or absolute path to the Accessor Repository file.
  3. Now if you press the 'Record' button, Sahi will record using Accessor Repository.
From 6.0.0 onwards, Accessor Repository is now tightly integrated in Controller itself.

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

Sahi Controller - Playback tab If not already open, open the Sahi Controller (ALT-DblClick on the page).
  1. Enter the script name first_script.sah in the 'File:' field (with the help of the autocompletion feature).
  2. Select appropriate Start Mode to run a script.
    infoNote: Start Mode is only avilable when Sahi Pro Desktop Add-on is installed.
    • Desktop Browser mode is used to run a script which runs on desktop browser only.
    • Windows mode is used to run a script which runs on windows for desktop only.
    • Generic mode is used to run a script when _setMode already defined in the script.
  3. 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.
  4. Click 'Set'. This will navigate the webpage to the URL mentioned in the Start URL textbox.
  5. Wait for the page to reload.
  6. Click 'Play'.
Steps will start executing, and the Controller will be updated accordingly. Once finished, SUCCESS or FAILURE will be displayed at the end of the steps.

infoNote: 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. Reports logs suites list Click on any script to view specific logs. Reports log single script Clicking on a line in the logs will drill down to exact line in script. Reports log line of 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.
  1. Click on the link "from url" as shown in the figure
  2. infoNote: Start Mode is only avilable when Sahi Pro Desktop Add-on is installed.
  3. Provide the necessary Script URL and Start URL.

Clipboard Tab

You can use this tab to store small pieces of information.

Info Tab

This tab shows the basic information of Sahi Controller, Browser, Operating System and Java.