Layout verification APIs
abstract
The following APIs are used for testing the layout of a webpage.
It is useful to test responsive design.
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
$elementAPIs | array optional | element apis which user wants to ignore in layout. |
$elements | array optional | provide elements to take page layout of sections covered by these elements. |
Return Value
string | Represents page layout. |
Modes Supported :
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
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.
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
$filePath | string | Text file path.
Text file path. Relative path resolves relative to files folder of the current project. |
Return Value
two dimensional array of element stubs | Two dimensional array of elements |
Modes Supported :
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
Validates the page layout based on $data.
Parameters
$data | two dimensional array of element stubs | Elements in same row are considered horizontal. Elements in subsequent rows are vertically below elements in previous row. |
$threshold | integer | If the vertical distance between the top left of 2 elements is within threshold number of pixels, they are considered to be horizontally aligned. |
Return Value
boolean | true if the page layout is valid, else throws error |
Modes Supported :
Raw Script
// Example:
var $data = _readLayoutFile("page_layout.txt");
_verifyLayout($data, 10);
Sahi Pro Classic API :_verifyLayout
Layout verification example
Following is an example of a sample webpage and the samplepage_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);