Home » Sahi » Understanding Sahi Web Automation API – Chapter 2

Understanding Sahi Web Automation API – Chapter 2


Starting with Useful API in Sahi Web Automation Tool Open Source .

1. _setValue –  This API is used for entering any value in Object types like “textbox” , “textarea” , “password” , “emailbox” , “searchbox” , “numberbox” and many such kind objects where we need to enter some value in that particular field.

Textbox,Password_and_Textarea

Syntax of the _setValue = _setValue(el, val) = _setValue(element, value)

With respect to above syntax and the above image some examples to understand.

1. _setValue(_textbox(“firstname”),”Abhijeet”);

2. _setValue(_password(“password”),”1234abcd”);

3. _setValue(_textarea(“description”),”This is test description”);

Similarly you can write script of _setValue for objects where you need to add/enter some content, value, text etc.

2. _click – This API is used for clicking on any click-able objects having object type as “button” ,”submit”, “link” ,”reset”, “radio” , “checkbox” , “textbox” etc.

Click-able Objects

Syntax of the _click= _click(el, combo) = _click(element, combo)

combo is optional which can used for having keys like “CTRL” , “SHIFT” , “ALT” and etc.

With respect to above syntax and the above image some examples to understand.

1. _click(_button(“Click Me!”));

2. _click(_link(“Back”));

3. _click(_checkbox(“male”)); // This is not standard API of checking check box but can be checked using click API as well.

4. _click(_button(“Click Me!”), “CTRL”); // clicks with CTRL key pressed

5. _click(_radio(“other”));

6. _click(textbox(“firstname”));

Similarly you can write script of _click for other click-able objects as per your need.

Also similarly you can use doubleClick API for Double Click. Some time we need to double click on some objects where we can use this API directly.

3._setSelected – This API used for selecting any value from Combobox or Multi Selection from combobox .

Selection_Objects

Syntax of the _setSelected= ( element, option_identifier, isMultiple)

option_identifier: Option’s text, id or index; can also pass an array of options for multi-select

isMultiple: true for multiselect, optional for single select

With above image and syntax some example

_setSelected(_select(“SingleSelection”), “01”);
_setSelected(_select(“SingleSelection”), 1); // Selects the second option in a select box
_setSelected(_select(“MultiSelection”), “02”); // Selects 02 in a multiselect box
_setSelected(_select(“MultiSelection”), “01”, true); // Selects 01 also in the multiselect box
_setSelected(_select(“MultiSelection”), [“01”, “02”]); // Unselects previous and selects 01 and 02 in a multiselect box
_setSelected(_select(“MultiSelection”), [1,2,3]); // Unselects previous and selects the second, third and fourth options in a multiselect box
_setSelected(_select(“MultiSelection”), [“03”], true); // Keeps previous options selected and selects “03”  also.

4. _check-  This API is used to checking the check box .Where ever you will find check box there you can use _check API to check the required field.

Checkbox_Objects

Syntax of the _check= _check(el)=_check(element)

Some examples using above syntax and above image.

_check(_checkbox(“firstcheckbox”));

_check(_checkbox(“thirdcheckbox”));

similarly we can use _uncheck API for unchecking checked Checkbox .

Syntax of the _uncheck= _uncheck(el)=_uncheck(element)

Some examples using above syntax and above image.

_uncheck(_checkbox(“secondcheckbox”));

5. _log- This API is used to print message in generated report/logs. Like Success message, Failure message, Custom messages.

We can use this API when we want to print messages in reports/logs after successful execution or success of “assertion” or “checkpoint” or “verification point”. Similarly for Failure messages and Custom messages.

Syntax of the _log= _log (message, type)

message – The message you want to print in Logs or Reports.

type- type of message like success, failure, error, info, or custom to custom5 .

as per the type , colour of the message varies like for success ,  message is in green colour for failure ,  message is in red colour  and so on.

Examples of _log API to have idea about some messages.

_log(“This is success”, “success”); // Display “This is success” as a green bar in the playback log.
_log(“This is failure”, “failure”); // Display  “This is failure” as a red bar in the playback log.
_log(“This is error”, “error”); // Display  “This is error” as a red bar in the playback log.
_log(“This is info”, “info”); // Display  “This is info” without any colour, in the playback log.
_log(“This is custom”, “custom”); // Display  “This is custom” in a different color on the logs. Use “custom”, “custom1”, “custom2” … “custom5” for different colors.

In the next Chapter we will see Next APIs  in detail.

Comments and Feedback always welcome ! 

I learned and explored through http://sahi.co.in and Documentations provided on site.  Here I am just sharing my knowledge in my language. 

For More Information Visit   http://sahi.co.in  and Thanks to Narayan and Tyto Software Pvt. Ltd team for making wonderful tool for Web Automation tool.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s