Skip to content
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.Flowcharts is retired. Current docs
Get Free Trial
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.

Layout verification APIs

The following APIs are used for testing the layout of a webpage. It is useful to test responsive design.

Modes Browser

Returns string representing page layout. User can provide the element apis as a first argument which he wants to ignore in layout. It needs to be used with _writeFile followed by _readLayoutFile and _verifyLayout.

Parameters

NameTypeDescription
$elementAPIsarrayoptionalelement apis which user wants to ignore in layout.
$elementsarrayoptionalprovide elements to take page layout of sections covered by these elements.

Returns

stringRepresents page layout.
Raw script
// Example:
var $all = _getLayout(); //returns string representing page layout
_writeFile($all, "D:/getLayout.txt", true); //writes returned string to text file
var $temp = _readLayoutFile("D:/getLayout.txt");
//read the layout text file and return a 2 dimensional array of elements
_verifyLayout($temp,9); //verifying the page layout and layout from _getLayout
var $data = _getLayout(["_heading2", "_div", "_row", "_cell"]); //ignoring (_heading2,_div, _row and _cell) from page
_writeFile($data, "D:/getLayout.txt", true); //writes returned string to text file
var $temp = _readLayoutFile("D:/getLayout.txt");
//read the layout text file and return a 2 dimensional array of elements
_verifyLayout($temp,9); //verifying the page layout and layout from _getLayout
var $all = _getLayout(null, [_div("section"), _div("new-section")]); //returns string representing page layout of sections covered by _div("section") and _div("new-section")] elements.
var $all = _getLayout([_span], [_div("section"), _div("new-section")]); //returns string representing page layout of sections covered by _div("section") and _div("new-section")] elements ignoring _span apis.

Sahi Pro Classic API _getLayout

Modes Browser

Reads the layout text file and returns a 2 dimensional array of elements. The layout file is a simple way of defining layout in a text file.

Elements on a line are treated as horizontally aligned. Elements higher up in the layout file are vertically above elements defined on a lower line.

Parameters

NameTypeDescription
$filePathstringText file path. Relative path resolves relative to files folder of the current project.

Returns

two dimensional array of element stubsTwo dimensional array of elements
Raw script
// For example, in
_cell("Python Cookbook"),_cell("7"),_cell("Rs. 350"),_textbox("q[2]")
_button("Add"),_button("Clear"),_button("Logout")

Sahi Pro Classic API _readLayoutFile

Modes Browser

Validates the page layout based on $data.

Parameters

NameTypeDescription
$datatwo dimensional array of element stubsElements in same row are considered horizontal. Elements in subsequent rows are vertically below elements in previous row.
$thresholdintegerIf the vertical distance between the top left of 2 elements is within threshold number of pixels, they are considered to be horizontally aligned.

Returns

booleantrue if the page layout is valid, else throws error
Raw script
// Example:
var $data = _readLayoutFile("page_layout.txt");
_verifyLayout($data, 10);

Sahi Pro Classic API _verifyLayout

Following is an example of a sample webpage and the sample page_layout.txt

page_layout.txt

_cell("Title"),_cell("In stock"),_cell("Cost"),_cell("Add quantity to cart")
_cell("Core Java"),_cell("5"),_cell("Rs. 300"),_textbox("q")
_cell("Ruby for Rails"),_cell("12"),_cell("Rs. 200"),_textbox("q[1]")
_cell("Python Cookbook"),_cell("7"),_cell("Rs. 350"),_textbox("q[2]")
_button("Add"),_button("Clear"),_button("Logout")

verify_layout.sah

_navigateTo("http://sahi.co.in/demo/training/books.htm");
var $data = _readLayoutFile("page_layout.txt");
_verifyLayout($data, 10);