Knowledge Base Article

> Knowledge Base > Rapise

Sometimes when you are running Rapise tests you need to run direct database queries to prepare the data in the test application, or you need to make queries against the database to verify that some user interactions left the data in a specific state.

The sample script below illustrates how you can call database queries directly from the Rapise scripting editor:

function ExecuteQueries()
{
  DP = "SQLOLEDB";
  DS = "MySQLServer";
  DB = "NORTHWIND";

  adOpenForwardOnly = 0;
  adLockReadOnly = 1;
  adCmdText = 1;
  try
  {
    var objRs = new ActiveXObject("ADODB.Recordset");
  }
  catch (e)
  {
    alert("ADODB namespace not found.");
    exit(0);
  }

  strConn =  "Provider="         +DP+
            ";Initial Catalog="  +DB+
            ";Data Source="      +DS+
            ";Integrated Security=SSPI;"
  strComm = "SELECT ProductID,ProductName,UnitPrice "+
            "FROM Products " +
            "WHERE CategoryID = 7"  // select Produce

  objRs.open(strComm,
             strConn,
             adOpenForwardOnly,
             adLockReadOnly,
             adCmdText);

  objRs.MoveFirst();
  while (objRs.EOF != true)
  {
    alert(objRs("ProductID")+"\t"
         +objRs("ProductName")+"\t"
         +objRs("UnitPrice"));
    objRs.MoveNext();
  }

  objRs.Close
  objRs = null;
}


function alert(str)
{
  WScript.Echo(str);
}
Article Info
  • Last Updated: 3/8/2013
  • Article ID: KB39
  • Views: 3137