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

//Loop through the rows
    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:

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:

// Extract all data from the Balance table
function ExtractTableData()
    // Array that will contain all rows
    var tableData = [];
    // Get all rows from the table
    var rows = SeS('Table')._DoDOMQueryXPath('./tr');
    Tester.Message("Rows count:"+rows.length);
    // Extract valuable data from the table into 'TableData' structure
    for(var i=2; i<rows.length-2; i=i+2)
        var cells = rows[i]._DoDOMQueryXPath('./td');
        // Each row is a structure with fields: project-id, name, description
        // Create empty structure to contain row data
        var rowData={};
        // And fill it according to known structure
            // Cell #1 - PROJECT_ID
            rowData.projectId = cells[1].GetInnerText();
            // Cell #2 - NAME
   = cells[2].GetInnerText();
            // Cell #3 - DESCRIPTION
            rowData.description = cells[3].GetInnerText();
        // Finally add the row to the array
    return tableData;