Using Sahi)

Source: Internet
Author: User
Using Sahi-

Before you start-prerequisites 
Java 1.5 or above is needed for running Sahi.

Download Sahi 
Download Sahi V3 (2009-11-30) from SourceForge

Install Sahi 
Unzip sahi.zip to a desired location

Start proxy of Sahi:

Windows:-go to <sahi_root>/userdata/bin and run start_sahi.bat
Linux-go to <sahi_root>/userdata/bin and run start_sahi.sh

Note that by default Sahi uses port 9999. This can be modified through Sahi. Properties

Configure the browser: 
You need to change your browser's proxy setting to use Sahi's proxy.

Firefox:

  • Go to tools> Options> advanced> network> connection settings>
  • Set to "manual proxy configuration"
  • Set "HTTP proxy" to "localhost"
  • Set "Port" to "9999". (This setting can be modified through/config/Sahi. properties)
  • Do the same for "SSL Proxy" too, if you want to record and playback HTTPS sites
  • Keep "use the same proxy for all protocol" unchecked as Sahi does not understand protocols other than HTTP
  • Note: "No proxy for" shocould not have localhost in it.

Internet Explorer:

  • Go to tools> Internet Options> connections> LAN Settings>
  • In "Proxy Server" section, check "use a proxy server for your LAN"
  • Click on "advanced"
  • For http: Set "proxy address to use" to "localhost" and set "Port" to "9999"
  • For secure: Set "proxy address to use" to "localhost" and set "Port" to "9999" (if you want to test HTTPS sites too)
  • Clear out anything in "do not use proxy server for addresses beginning :"
  • OK
  • Leave "Bypass proxy server for local addresses" unchecked
  • OK> OK

Recording through Sahi

  • Press ALT and double click on the window which you want to record. sahi's controller window will pop up. (if that does not work, press Ctrl and ALT keys together and then double click. make sure popup blockers are turned off. for further trouble shooting have a look at this help link .)
  • On the controller, go the record tab (wocould be selected by default ).
  • Give a name for the script, and click 'record'
  • Navigate on your website like you normally wocould. Most actions on the page will now get recorded.
  • Add an assertion:
    O move the mouse over any HTML element while pressing CTRL key. The accessor field will get populated in the controller.
    O click the "assert" button to generate assertions for the element. They will appear in the "evaluate expression" box.
    O click "test --->" to check that the assertions are true. you can evaluate any JavaScript using "evaluate expression" and "test ---> ". actions saved med via the Controller will not be automatically recorded. only actions synchronized med directly on the page are automatically recorded. this lets you experiment on the webpage at recording time with out impacting the script.
    O once satisfied, click on "APPEND to script". This will add the assertions to the script.
  • Click "stop" to finish recording.

Note that the controller can be closed and reopened at any time, without disrupting recording.

View the recorded script

The recoded script can be viewed and edited by opening the. Rated file in the <sahi_root>/userdata/scripts directory. Sahi scripts are simple text files which use JavaScript syntax.

The script can be edited even while recording, so that logical segregation into functions etc. can be done as recording happens.

Playing Back

  • Open the Sahi controller (Alt-dblclick on the page ).
  • Enter the script name in the "file:" field (with the help of the autocompletion feature ).
  • Enter the start URL of the test. If you had started recording from the http://www.google.co.in, use that URL.
  • Click 'set '.
  • Wait for the page to reload.
  • 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.

Note that the controller can be closed at any time, without disrupting playback.

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 neatly formatted in HTML.

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

That is it! You have successfully recorded and played back a Sahi script!

Help! The Sahi controller does not come up

The Controller will only come up if the web page has been modified by the Sahi proxy

Try the following:

  • Refresh the browser and check
  • Force reload (override cache ),
    Firefox: Ctrl + F5 or Ctrl + Shift + R Internet Explorer: Ctrl + F5
    Or clear the browser cache manually and reload.
  • Make sure popup blockers are turned off.
  • If you are surfing the intranet on IE:
    Go to tools-> Internet Options-> connections-> LAN Settings. There, make sure that "Bypass proxy for local addresses" is unchecked.
  • If you are surfing an HTTPS site, make sure that the proxy is configured for SSL/HTTPS on your browser. also have a look at https/SSL sites do not work properly
  • If using IE7, surfing to http: // localhost: Port and http: // 127.0.0.1/port may bypass Sahi. Try using your machine name instead.
Configuration Sahi and improve test speed
  • Replace Sahi. bat with the one attached.
  • Modify Sahi. BAT and setup java_home, using jdk6 will have better performance.
  • Add sahi-patch.jar to % sahi_home %/lib
    • You can download Sahi. BAT and sahi-patch.jar
Sahi script
  • Verify the user name and password
    Function Test ($ username, $ password) {_ setvalue (_ Textbox ("j_username"), $ username); _ setvalue (_ password ("j_password "), $ password );}
    Test ("root", "root ")
    _ Click (_ submit ("login "));
  • Contains another script file
    _ Include ("path/common_functions._3 ");
  • Define the variable name and assign values
    VaR $ variablename = value;
    Or
    VaR $ variablename;
    $ Variablename = value;
  • Print Information on the console
    Function printthroughjava (s) {packages. java. Lang. system. Out. println ("Through Java:" + S );}
    Printthroughjava ("Hi There ");
    // Print through Java: Hi there on the console
  • If Condition Statement
    VaR $ I = 2;
    If ($ I = 1) {packages. java. lang. system. out. println ("I =" + $ I);} else {packages. java. lang. system. out. println ("I =" + $ I );}
    }
  • For Loop statement
    /* This loop will login with user1, password1, user2, password2 etc.
    Login and logout are M functions .*/
    VaR $ max = 10;
    For (VAR $ I = 0; $ I <$ Max; $ I ++) {packages. java. lang. system. out. println ("I =" + $ I );}

    * While loop statement
    $ I = 0;
    While ($ I ++ <10) {packages. java. Lang. system. Out. println ("I =" + $ I );}
    }
  • Capture exceptions
    Try {_ click (_ Link ("does not exist");} catch (e ){
    _ Log ("exception occur"); // display this row and execute the next sentence
    // _ Logexception (E); // No information is displayed
    Packages. java. Lang. system. Out. println ("excute next step ");
    $ I = 0;
    While ($ I ++ <10) {packages. java. Lang. system. Out. println ("I =" + $ I );}
    // _ Logexceptionasfailure (E); // a message indicating a failure is displayed.
    }

Using Sahi)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.