Sahi Pro - Layout verification APIs

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

_readLayoutFile

Since Sahi Pro: 5.0
Since Sahi OS: NA

_readLayoutFile($filePath)

Arguments
$filePathstring Text file path.

Details

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.

For example, in
_cell("Python Cookbook"),_cell("7"),_cell("Rs. 350"),_textbox("q[2]")
_button("Add"),_button("Clear"),_button("Logout")

_cell("Python Cookbook") is to the left of _cell("Rs. 350")
and
_button("Add") is vertically below _cell("Python Cookbook") (not necessarily within _cell("Python Cookbook")'s boundaries though)
and
_button("Clear") is to the right of _button("Add")

This can be used to verify the layout of the following page:

info This api is used with _verifyLayout.

//Read the layout text file and store it in the variable
var $data = _readLayoutFile("page_layout.txt");

_verifyLayout

Since Sahi Pro: 5.0
Since Sahi OS: NA

_verifyLayout($data, $threshold)

Arguments
$data2 dim array 2 dimensional array of elements. Elements in same row are considered horizontal. Elements in subsequent rows are vertically below elements in previous row.
$thresholdinteger If the vertical distance between the top left of 2 elements is within threshold number of pixels, they are considered to be horizontally aligned.

Details

Validates the page layout based on $data.
Example:
var $data = _readLayoutFile("page_layout.txt");
_verifyLayout($data, 10);

Layout verification example


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);