Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, windows and java based applications. Get your 30 day free trial.

Discuss your Sahi Pro usage patterns, best practices, problems and solutions. Help others solve their problems and seek help from the community when needed. If you need specific support on your application, please email support @ sahipro.com

Coding standards

manasa.msmanasa.ms Members
edited November -1 in Sahi - Open Source
Hi,
Can anyone tell me what coding standards do we need to follow while writing scripts using sahi.

Comments

  • narayannarayan Administrators
    Hi Manasa,

    Follow the coding standards of javascript.

    A brief summary:
    1) Function names are camelCase
    eg. function loginAsAdmin ()
    2) There is a single space on both sides of =+
    eg. var $total = $one + $two;
    3) Every block of code should be indented.
    4) A space is required after a punctuation mark and there should be no space before.
    eg. var $colors = ["blue", "red"];
    eg. for (var $i = 0; $i < 10; $i++)
    5) Semicolons are good after each statement
    6) For global variables, use $g_ or some similar prefix
    eg. $g_userName
    7) For constants, use full capitals and underscores
    eg. $FIVE_SECONDS = 5000;
    8) Indentation should be as under:
    function login(){
        if (_exists(_textbox("username"))) {
            _setValue(_textbox("user"), "test");
            _setValue(_password("password"), "secret");
            _click(_submit("Login"));
        }
    }
    

    Try to keep functions pertaining to a particular web page in a single sah file. You may end up with a few sah files, each one having functions related to a particular page. That way it is easy to modify only the pertinent script if any browser element has changed. Eg. you may have a user_lib.sah and login_lib.sah

    Use _include to include the relevant page based sah files to create a flow or scenario. You may have scenario1.sah including login_lib.sah and user_lib.sah. Try not to have any page specific components in scenario1.sah.

    Hope that helps. If anyone has any other inputs/variations please post.

    Regards,
    Narayan
  • Hi Narayan,
    Thanks for the Information.
This discussion has been closed.