PMC:QA:Research Sahi

From ADempiere
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.

Sahi

Sahi is an automation and testing tool for web applications, with the facility to record and playback scripts. Sahi runs on any modern browser which supports javascript. Read More:[1]

Sahi how-to

Download + Install

  • Download Sahi from: http://sourceforge.net/projects/sahi/files/
  • For example: install_sahi_v35_20110404.jar .
  • Install the package by issuing at the console java -jar install_sahi_v35_20110404.jar.
  • Follow the instructions.
  • the installed package will be deployed under the directory you pinpointed at installation time
    • Scripts are stored under sahi/userdata/scripts and have a suffix .sah
    • Important configuration files are stored under /sahi/config
    • Executable file: sahi.sh

Start Sahi

now you can start Sahi in console

  • open a console and go to directory where Sahi has been installed
  • execute Sahi (./sahi.sh)
workbox bin # ./sahi.sh
--------
SAHI_HOME: ..
SAHI_USERDATA_DIR: ../userdata
SAHI_EXT_CLASS_PATH:
--------
Sahi properties file = /mnt/sda4/Sahi/sahi/config/sahi.properties
Sahi user properties file = /mnt/sda4/Sahi/sahi/userdata/config/userdata.properties
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi0
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi1
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi2
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi3
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi4
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi5
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi6
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi7
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi8
Copying profile to /mnt/sda4/Sahi/sahi/userdata/browser/ff/profiles/sahi9
>>>> Sahi started. Listening on port: 9999
>>>> Configure your browser to use this server and port as its proxy
>>>> Browse any page and CTRL-ALT-DblClick on the page to bring up the Sahi Controller
  • Then you have to start the dashboard: ./dashboard.sh

You can also can start Sahi graphically via Program menu:

  • A console is opened
Sahi properties file = /data2/app/sahi/config/sahi.properties
Sahi user properties file = /data2/app/sahi/userdata/config/userdata.properties
>>>> Sahi started. Listening on port: 9999
>>>> Configure your browser to use this server and port as its proxy
>>>> Browse any page and CTRL-ALT-DblClick on the page to bring up the Sahi Controller
-----
Reading browser types from: /data2/app/sahi/userdata/config/browser_types.xml
Chrome was not found at /usr/bin/google-chrome
-----
/usr/bin/firefox -profile "/data2/app/sahi/userdata/browser/ff/profiles/sahi0" -no-remote http://sahi.example.com/_s_/dyn/Driver_initialized
Apr 11, 2011 10:39:00 AM net.sf.sahi.ssl.SSLHelper getKeyManagerFactoryForRemoteFetch
INFO: No SSL Client Cert specified
  • a dashboard/launch applet is started with the possibility of
    • starting Sahi on a browser
    • Configure Sahi by editing configuration files
    • See scripts
    • See logs
    • See DB logs

Sahi launcher.png

Test with Sahi

  • Run Sahi from the console or start menu. The Sahi Dashboard will appear with a list of available browsers.
  • You may have to click "Configure" and edit the xml to enable all the browsers.
  • Click on one of them and the browser window will open:

Sahi browser.png

  • VERY IMPORTANT!!!!!: THE SAHI BROWSER SAYS THE SAHI CONTROLLER IS OPENED WITH ALT-Double Click. THIS IS WRONG! IT MUST BE Ctl-Alt-Double click
  • Sahi will automatically configure the proxy to use localhost:9999; other features of the browser may be limited.
  • The browser will open the site http://sahi.example.com/_s_/dyn/Driver_initialized.
  • Ctl-Alt-Double Click in this page to open the Sahi controller:

Sahi7.png

Recorded Sahi script

  • type in the browser the URL you want to test
  • press the Go button
  • open theSahi controller with Ctl-Alt-Double Click on this page
  • select the Record tab
  • put in "Script Name"(e.g. test_forum)
  • click Record button to start recording
  • Recorder will record your operation.
  • If you want to check (assert) a value
    • hover over the field, Ctl-Click on the application
    • press the Assert button on the recorder
    • press the Test button on the recorder to see what the result will be
    • and -if the test is successful, press the button Append to Script.
    • you may change the data before appending

Sahi8.png

Example of a recorded Sahi script.

_setValue(_textbox("q"), "sahi forums");
_click(_submit("Google Search"));
_assertExists(_link("Sahi - Web Automation and Test Tool"));
_click(_link("Sahi - Web Automation and Test Tool"));

Sahi Controller - Playback tab

  • It may confuse you that the "Playback" tab seems to be inactive.
  • You can press it anyway.
  • The same applies to the other tabs ("Info" and "New").
  • Also, when you press the "File" combo-box, all files under the Script Directory are displayed.
  • Type in the "Start URL" field the URL you are testing (e.g. http://asds2.adempiere.de:8080/webui/index.zul)
  • Press the "Set" button
  • Wait until the page refreshes
  • Press the "Play" button

Sahi9.png

Be sure to check that you have enabled third party cookies in the Firefox, it is required to work playback properly.

Playback logs for single script run via Controller

Sahi10.png

References

Tests

( Put the newest entries at the top - like a blog )

  • MJMcKay 12:58, 27 May 2011 (UTC) Here is another example script to create an order and check the grand total. PMC:QA:Research Sahi:Sample Script - Create and Test Order. I found that regular expressions work quite well in selecting fields. Also, the SAHI api functions _near and _in help alot. See the best practice section of the PMC:QA:Research Sahi:Test Plan.
  • Kthiemann 11:44, 27 May 2011 (UTC) I managed to run the scripts. I had to set the userdata.properties as described below and add some _assertExists() / _assert(_isVisible()) / _wait() to the script. It is important also to use the main menu tree for navigation. After that it runs in Firefox and Chrome. IE still won't work but that's because of the blocked content problem.
  • Kthiemann 13:16, 26 May 2011 (UTC) I had problems with a quite simple task. Login, navigate to an order, logout. The problem here is similar to what Mario reported. The behaviour is depending on the browser (Firefox 3.6, Firefox 4, IE8, Chrome) I was able to login with all browsers but when I tried to navigate to an order it won't open it (on Firefox). On Chrome the order is opened but the logout fails. On IE the script works but you have to click away the blocked content warning on every single step. The script is:
_setValue(_textbox(0), "GardenAdmin");
_setValue(_password(0), "GardenAdmin");
_click(_image("Ok24.png"));
_click(_image("Ok24.png"));
_click(_link("Sales Order"));
_click(_link("Log Out"));
  • MJMcKay 02:27, 13 April 2011 (UTC) Some thoughts on organizing and planning the test scripts. See PMC:QA:Research Sahi:Test Plan.
  • Rvergara 14:28, 12 April 2011 (UTC) Installation of Sahi on Windows XP, recorded a simple script to automate login to http://www.testadempiere.com/webui . worked well but Sahi has problems displaying the google calendar as indicated in other comments around. Performance was quite good (wonder if it is related to executing it in XP)
  • Mario Calderon 22:17, 11 April 2011 (UTC) Got the installation done and Sahi running. Executed Mike's script including time params changes. Though it runs, it takes a long time between steps: more than 5 minutes until BP location edit.
    • I run tests on my own Application Server:
      • When klicking at menu entries, Sahi playback seems to fail when clicking on the node (it produces a code like _click(_span("z-tree-ico z-tree-tee-open")); )
      • Playback works when clickig directly on the node name (it produces a code like _click(_div("System Admin")); )
  • MJMcKay 02:17, 11 April 2011 (UTC) Got the test to work! See PMC:QA:Research Sahi:Sample Script - Login Remember Me. For some reason the script wasn't finding the log-in string after the page load but it would find the Sales Order link. If I created and canceled a sales order, I was able to test the log-in string. I also changed the user.properties as follows. The page load times are a bit short so I found adding _wait(ms) calls helped. If I adjusted the script execution parameters instead, the script would run too slowly. Apart from the waits and opening the sales order, the script runs faster than I can follow visually.
# Script execution params

#Time (in milliseconds) delay between steps
script.time_between_steps=100
#Time (in milliseconds) delay between retries once an error occurs
script.time_between_steps_on_error=1000
#Number of retries once an error occurs
script.max_reattempts_on_error=5
#Number of cycles Sahi will wait for the page to load before it proceeds with execution
#Time spent is (script.max_cycles_for_page_load x script.time_between_steps) milliseconds
script.max_cycles_for_page_load=100
#No of times Sahi should wait for stability of AJAX and page loads before continuing. min value is 1
script.stability_index=1
  • MJMcKay 21:48, 10 April 2011 (UTC) Wondering if the limitations on frames from other domains is causing the problem. Is the google calendar the cause?
Framesets/pages with frames/iframes loading pages from multiple domains is not supported.
Sahi cannot handle pages which have other pages from different domains embedded in them using iframes or frames. So you cannot have a page from google.com having an iframe with a page from yahoo.com. Note that this is not the same as switching between domains, where you navigate from a google.com page to a yahoo.com page, which will work in Sahi.
# Script execution params

#Time (in milliseconds) delay between steps
script.time_between_steps=200
#Time (in milliseconds) delay between retries once an error occurs
script.time_between_steps_on_error=2000
#Number of retries once an error occurs
script.max_reattempts_on_error=5
#Number of cycles Sahi will wait for the page to load before it proceeds with execution
#Time spent is (script.max_cycles_for_page_load x script.time_between_steps) milliseconds
script.max_cycles_for_page_load=3000
#No of times Sahi should wait for stability of AJAX and page loads before continuing. min value is 1
script.stability_index=10
  • MJMcKay 13:13, 9 April 2011 (UTC): I've tried to write a simple test script PMC:QA:Research Sahi:Sample Script - Login Remember Me to log in to the adqa.adempiere.com system and test the "Remember Me" on the login window. Everything works well up to the point where the AJAX window is displayed, then the tests time out. There are a number of references to Sahi waiting for all processes to complete before it performs the tests. The Sahi code in concat.js is supposed to tell which processes will be long duration and ignore these but the script is still hanging.

Links