Accessing the Database Data
Rapise comes with a Database query global object that allows you to send SQL queries to a database and then iterate through the results. You drag the 'Database' global object into the script editor and then use:
- Database.DoAttach() - to make the database connection and specify the SQL query
- Database.GetRowCount() - to verify that there is data
- Database.DoSequential() - to loop through the dataset row by row
- Database.GetValue() - to get that row's data
Here is a complete example:
var success = Database.DoAttach('Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SpiraTest;Data Source=.', 'SELECT * FROM TST_PROJECT');
Tester.Assert('Successfully Connected', success);
var count = Database.GetRowCount();
Tester.Message(count);
while(Database.DoSequential())
{
var projectId = Database.GetValue("PROJECT_ID");
var name = Database.GetValue("NAME");
var description = Database.GetValue("DESCRIPTION");
}
Next we need to get the data from the user interface.
Verifying the Data in the UI
To verify the data in the user interface, we need to use the XPath approach outlined in this guide to dynamically access the rows of data in the HTML table that contains the data:
https://www.inflectra.com/Rapise/Guides/Working-with-HTML-Tables.aspx
You can then use the LEARN (CTRL+2) option to learn one of the cells in the datagrid and then adjust the XPATH of the learned object to actually point to the whole table.
Then you can use the following query to get all the rows in the table:
var rows = SeS('Table').DoDOMQueryXPath('./tr');
Tester.Message ("Rows count:"+rows.length);
Then for each row you can loop through all the cells to compare the data with that from the database query performed earlier:
function ExtractTableData()
{
var tableData = [];
var rows = SeS('Table')._DoDOMQueryXPath('./tr');
Tester.Message("Rows count:"+rows.length);
for(var i=2; i<rows.length-2; i=i+2)
{
var cells = rows[i]._DoDOMQueryXPath('./td');
var rowData={};
if(cells.length>=3)
{
rowData.projectId = cells[1].GetInnerText();
rowData.name = cells[2].GetInnerText();
rowData.description = cells[3].GetInnerText();
}
tableData.push(rowData);
}
return tableData;
}