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

Understanding Sahi Web Automation API – Chapter 3


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

1. _assertEqual – This API is used to compare Actual Value and Expected Value , If expected and actual values matches then it returns true and if not matches then it throws exception and print the log message which is given in _assertEqual.

 

assert

Syntax of the assertEqual = _assertEqual(“Expected Value”, “Actual Value”,”Message you want to print in log on exception”)

Expected Value – This is the value to match with actual value you are getting from Application.

Actual Value – This is the value you are getting from application to match with expected value.

Message you want to print in log on exception- This is the message you want to print in log when actual and expected values not matches and throws an exception. This field is optional.

With respect to above syntax and the above image we will see some examples.

1.  var $getactualvalue = _getText(_div(“Description:”));

_assertEqual(“Description:”,$getactualvalue );

2.  var $getactualvalue = _getText(_textbox(“description”));

_assertEqual(“Hi This is description.”,$getactualvalue );

3.  var $getactualvalue = _getText(_submit(“click me”));

_assertEqual(“Click Me!”,$getactualvalue );

4.  var $getactualvalue = _getText(_checkbox(“first”));

_assertEqual(“First”,$getactualvalue ,”This will print in log as Expected and Actual Value not matches”);

Note: Similarly, _assertNotEqual is working opposite to _assertEqual.

2. _assert –  This API is used to check condition with respect to particular object like _isVisible.

Syntax of the assert = _assert(“Condition”, “Message you want to print in log on exception”)

Condition– This is the condition to check for particular element and objects . If condition is true then it return value as true else throws an exception.

Message you want to print in log on exception– This is the message you want to print in log when condition fails and throws an exception. This field is optional.

With respect to above syntax and the above image we will see some examples.

1. _assert(_isVisible(_submit(“click me”)));

2. var $flag = _assert(_isVisible(_textbox(“description”),”Condition fails”));

if($flag==true)

{

_log(“Condition true”, “success”);

}

Note : Similarly _assertTrue works and opposite to it _assertNotTrue works.

3. _assertExists–  This API is used to check existence of the object or element in the application.

Syntax of the assertExists = _assertExists (Object ,  “Message you want to print in log on exception”)

Object -Existence of this object checked in the application

Message you want to print in log on exception– This is the message you want to print in log when  object not exist and throws an exception. This field is optional.

With respect to above syntax and the above image we will see some examples.

1. var $flag = _assertExists(_textbox(“description”),”Text box not exist”);

if($flag==true)

{

_log(“text box found”, “success”);

}

Note: Similarly opposite to _assertExists , _assertNotExists also works , see the below example.

1. var $flag = _assertNotExists(_textbox(“description:”),”Text box exist”);

if($flag==true)

{

_log(“text not found”, “success”);

}

4. _assertContainsText  – This API is used to check whether particular value is present in objects or present for particular objects. Or to check whether particular object contains the expected text.

e.g. If I want to check , Whether India is present in Country Dropdown. Then _assertContainsText is used.

Syntax of _assertContainsText-  _assertContainsText(expectedText, element/objects, “Message you want to print in log on exception”)

expectedText – Value or Text to check whether particular objects contains or not.

element/objects – Element in which expected value or text need to check.

Message you want to print in log on exception – This is message when particular text is not contained by object or element and throws and exception.

With respect to above syntax and the above image we will see some examples.

1.  _assertContainsText(“Hi This is Description.”,_textbox(“description”),”Text not present”);

Note: Similarly _assertNotContainsText works.

1.  _assertNotContainsText(“Hi This is.”,_textbox(“description”),”Text present”);

 

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