Sahi Script Editor
It can also be launched from the Sahi controller to edit the currently recorded script. A typical editor window will look like this.
This is the left-most panel in the editor and shows all the scripts, suites and other files in the scripts directory.
At the top of Navigator, there are three buttons. You can use them as follows:
Refresh: This button is used to refresh the directory so that newly added scripts are visible.
Link to Editor: If active, the name of script being edited will be scrolled to in the navigator menu.
Collapse: This will collapse the navigator and provide some additional space for the script editor.
Expand All: This will expand all scripts and sub-folders.
Collapse All: This will collapse all scripts and sub-folders.
The filter at the top of navigator is used to filter scripts based on the entered text. It can also be used to filter all suites and scripts.
All the scripts and suites are listed in a tree menu in the navigator. If you click on the name of a script or suite, it will open up for editing in the script editor. Also, if you right click on the name of script or suite, following menu is available.
Run: If playback properties are configured, it will start script execution. If not, it opens up the playback properties window. Once executed, scripts can be stopped by clicking on the "Stop All" button in the top menu. Open: Opens the current file. Logs: Opens the HTML logs for the current script. Docs: Opens the script in documentation mode. Rename: Makes the filename editable. Delete: Deletes the file. Cut: Cut the current file. Copy: Copy the current file. Paste: Paste the cut/copied file.
Script editor provides an interface to edit the Sahi scripts within a browser window. The editor integrates with function creator and context editor to provide an easy interface to refactor the scripts. To edit a script, simply select the script from the navigator and start editing in the editor. Editor provides different interfaces for scripts, scenario and suites.Errors in Scripts
The script editor also shows if there are any errors in your scripts. It shows a red cross sign at the line containing error. If you hover on the cross sign, it shows you more detail about the error. You can click on up and down arrow to move to next or previous error.
- Search for the function name.
- Select the file from which function is to be used. It is possible that same function is defined at multiple places.
- Provide the values for arguments.
- Click on Insert button to insert the function.
- In you want to insert the function call, end it with a semi-colon and move to next line, click on this option.
- You can also update the values of arguments and click on update button. This will update the values in script.
- If you want to open the file containing functions, you can click on Open button to open this file as a new tab.
- If the file containing function is not included, it shows up in red color. Click on include button to include the file.
String values in AR can be replaced in Sahi scripts since Sahi Pro v8.0.0 Use
replace2("oldString", "replacement")function to replace the desired string with any value. This will return a new AR value replacing the oldString. Original AR will be retained as such.
Eg: Let AR be
$TEXTBOX = "username";
_include api by specifying desired column name as second argument.
// including csv as AR file _include("my_AR.csv", "FrenchWeb"); _setValue($_TEXTBOX_USER, "test"); _setPassword($_PASSWORD_PASSWORD, "MgkKEQBU"); _click( $_SUBMIT_LOGIN);
|$_PASSWORD_PASSWORD||_password("password")||_password("mot de passe")|
- CTRL-Click on a function or AR key, opens its details in the Context Panel.
- In Scenario files, CTRL-Click on Key Word opens the Function Details dialog.
- Clicking the
Openbutton near the filepaths in the above dialogs, opens the relevant included file at the relevant line.
- CTRL-Click on file paths in _include lines, or in loadSahi lines in Scenario files, opens the file in Editor.
more:is used to show more arguments.
Remove Duplicates:is used to remove duplicates function parameters with same arguments.
Create JsDoc:it's purpose is to document the description of the function.
Add Function Call:will add function call for the function which is created. Unmark it, if you are calling the function in any other script or in a scenario file.
userdata/config/function_names.txtfile and select one of these while creating functions. This file can be edited using the Configure link on Dashboard and then selecting the file name from left navigation.
To search for usage of a function across the scripts folders, select the checkbox for function while searching. To search for usage of a variable across the scripts folders, select the checkbox for variable while searching. If you want to perform an exact match in search, select the textbox for exact search. If you want to search in specific set of files, you can provide the regular expression pattern in File pattern. For example, if search is to be performed only in .sah files, you can use *.sah as expression.
To replace a function or variable, search for the function or variable first. Once the results of search are available, provide the string which will replace the searched text in Replace With box. Select the files in which replacement is to be done. If you want to make the change in all the files, select all files by clicking the top checkbox. Click on Replace button and Sahi will show you an alert asking if you want to actually replace. Click Yes to replace and Cancel to Cancel the operation.
In the image above, the scenarios with 'admin' OR 'customer' tag AND with 'smoke' tag will be filtered out and executed. Following tools are available while editing a scenario file.
1. Insert Testcase: Inserts a blank test case 2. Load Sahi library: Inserts the syntax to include a function library. You can press CTRL and click on the name of included file to open it up in a new tab of editor. 3. Function Details: Shows all the details about the function that was selected before cliking the button. It shows all the files containing the function. If the file containing the function is not included, you can click on the include button to include the file. You can also press CTRL and click on the function name to see it's details. To set argument:parameter pair, check Set as field:value.
- To define a function with pass by argument:
- To define a function with pass by object:
To configure playback properties, click on the Playback button in the top menu. It opens up the basic configurations required for the script execution.
- If the user has selected some scripts/suites in the Navigator, and clicked on Playback, Sahi will automatically create a suite (selectedScripts.suite) containing the selected scripts/suites, and selectedScripts.suite will be chosen for playback.
- If the user has selected one script/suite in the Navigator, that individual script/suite will be chosen for play back.
- If no scripts have been selected in the Navigator, the script or suite file that is currently open (in focus) in the Editor will be chosen for playback.
At the very minimum, you need to provide a start mode, start URL and browser name to execute the script. Script directory and script file fields show the file for which play button was clicked.
- Select appropriate
Start Modeto run a script.infoNote:
Start Modeis only avilable when Sahi Pro Desktop Add-on is installed.
Desktop Browsermode is used to run a script which runs on desktop browser only.
Windowsmode is used to run a script which runs on windows for desktop only.
Genericmode is used to run a script when _setMode already defined in the script.
- Select the browser from the dropdown. This lists all the browsers configured on your machine. In case you are providing multiple nodes for distributed playback, this will list browsers from all nodes. One can choose more than one browser to run the script/suite in.
- Enter the Start URL.
- Click on the Play button to play the script. The default setup (Run in parallel with Threads as 5) lets you run the scripts in parallel with 5 simultaneous instances.
- If you wish to run the scripts in the suite one after another within the same browser session, select "Run sequentially in single browser session". This will open a browser window and execute scripts one after the other on this same browser window. The browser window will only be closed at the end of the suite. Use this with caution.
- If you wish to run the scripts in the suite one after another but in different browser sessions, select "Run in parallel" with Threads as 1. Browser window will be closed after each script.
- To distribute the playback across multiple machines, check the
Run distributedradio button.
- Click on the button to configure nodes for playback.
- Provide the machine names and port numbers.
- To use the node for execution, check the "Use" checkbox for the node. (Sometimes you may may want to exclude 1 or 2 nodes from the nodes list. You can uncheck that particular node without deleting the entry.)
- Click on Update button. This updates the node information for execution.
- Click on Close button to close the node configuration window.
- This allows you to add more space for additional nodes.
- Set the number of threads to be executed on each Node
- By default Sahi will consider the localhost as the master node. If you want to use a different master, click the checkbox for Use Different Master.
- Provide the machine name to be used as the host.
- Provide the port (default 9999).
- Offline Reports: You can configure the storage of offline logs by setting the paths for various types of reports.
- Click on the button to bring up the Logs Info Editor.
- Provide the location for storing the logs.
- Unless you click on Use, the settings won't be considered. Click the Use checkbox for the type of logs that you want.
- Click on update to update the Offline logs settings.
- Once updated, you can close the Logs Info Editor.
- Show Periodic Summary: You can get a regular update of the suite status by enabling Show Periodic Summary. If the script is being played back from the Editor itself, the regular updates appear on the bottom right corner of the screen. This functionality is also updated in the sample Ant file. You can read more about it here.
- Retry Count:
It provides the privilege to retry each of the failed and aborted scripts immediately after its execution. User can specify the retry count. Default count is 0.
- ABORTED: Specify the times for the ABORTED scripts should retry.
- FAILURE: Specify the times for the FAILURE scripts should retry.
- Send Email Reports:
You can enable sending email reports after script run on Success, Failure or both.
danger The user needs to edit the email.properties and set the various properties. By default, none of the properties are set.
- Click on the checkbox to enable sending email reports.
- Select the trigger for sending email reports. It can be either success or failure or both.
- Periodic emails: For a long running suite, users can configure emails to be sent periodically while the suite run is in progress. Click on checkbox for sending out periodic emails. In the dropdown below, select the time interval at which the email should be sent.
- Sahi uses the properties file present at
userdata/config/email.propertiesto send the emails. You can click on this button to edit the email.properties file. You can change the properties file using other text editor as well.
- JS Code Coverage: You can enable the JS Code Coverage at script/suite run by enabling the pick box. JS Code Coverage has been described in detail here.
- Extra Parameters: You can pass extra parameters to script or suite before playback in form of key value pairs. These values can then be used within the scripts.
- Click on the button to open Extra Param Editor.
- Provide the name and value for the parameters.
- Click on Mask checkbox to hide the values of parameters from logs. This is useful for masking information like passwords.
- Update button populates the parameters and their values in Extra Parameters text box. This will be then passed on to the script.
- Click on close to close the Extra Param Editor.
- If you would like extra space for parameters, you can click the button to add an extra row.
- User Defined Id: You can provide a unique ID to be used as User Defined Id for the script//suite run.
This can be displayed in any type of log by changing
<xsl:param name="showUserDefinedId" select="'false'" />
in the suites_list.xsl of userdata\config\reports\
<xsl:param name="showUserDefinedId" select="'true'" />
. can be html, xml etc
Schedulebutton from the dropdown.
- Choose a date and time from the dropdown. Click OK to set the date.
- Provide a description(optional) for the test.
- Click on Schedule to schedule the test.
|CTRL + S||Save current file|
|ALT + Up Arrow||Move current line up|
|Alt + Down Arrow||Move current line down|
|CTRL + D||Delete the current line|
|CTRL + F||Search in script|
|CTRL + /||Comment selected lines|
|CTRL + ALT + Up Arrow||Copy current line above|
|CTRL + ALT + Down Arrow||Copy current lown on next line|
|CTRL + L||Opens a dialog box to enter line number. Enter line number and press enter to go to line.|
Debugoption from the dropdown next to
Runbutton in Script Editor.
When that script is executed from the editor, it will reach the breakpoint and pause the playback. Sahi controller will launch at that point and then you can go to playback tab and either step over next lines or click on play to resume playback. 1. In the above image, the script is paused at breakpoint number 1. 2. Click on step to execute next statement.
To clear all breakpoints across all scripts, you can click the 'clear all breakpoints' button in the script editor. This button can be found in the top menu.
Now you can use the encoded password in _setPassword Api.