Forum Discussion

NT's avatar
NT
Contributor
10 years ago

How to refresh a DB Table Variable in a Loop

Hi,

 

I would like to continue to a second KeywordTests base on a field that is update in a Database.

 

So in terms of word.

 

I execute Test1 and would like to execute Test2 only if the Field <Statut > in the Table CPF_Statu is equel to <P>.

 

I can access to the field in the Database using DB Table variable type but it never refresh the content of the field. It stays always on the same first read.

 

How can I do that by script or by KeywordTests ?

 

Best regards

  • Without seeing your setup in person I would do something like this.

     

    At the end of  Test1 Run this script (obviously filling in the details).

     

    function checkStatut() {
      var dbConnection,
          record,
          statut;
      
      dbConnection = ADO.CreateADOConnection();
      dbConnection.ConnectionString = "connectionString"
      dbConnection.LoginPrompt = false;
      dbConnection.Open()
      
      record = dbConnection.Execute_("sql query");
      statut = record.Fields("Statut").Value;
      
      if (statut == "<P>")
    	KeywordTests.Test2.Run(); //assuming Test2 is a keyword test
    }
  • NT's avatar
    NT
    10 years ago
    thanks it work fine, but now if the Statut become at value P only after a certain time so it means that I need to refresh the information of the statut by reading the information in the database until it becomes at value P. It is a delay treatment. is it possible to use a Loop to wait until the statut become at value P ? thanks a lot for your help !!!
  • Sure try something like this:

     

    function checkStatut() {
      var dbConnection,
          record,
          statut;
      
      dbConnection = ADO.CreateADOConnection();
      dbConnection.ConnectionString = "connectionString"
      dbConnection.LoginPrompt = false;
      dbConnection.Open()
      
      while (statut != "<P>") {
        record = dbConnection.Execute_("sql query");
        statut = record.Fields("Statut").Value;
      
        if (statut == "<P>")
       	  KeywordTests.Test2.Run(); //assuming Test2 is a keyword test
      }
    }
  • cunderw's avatar
    cunderw
    Community Hero

    From the TC documentation:

     

    To enable the database checkpoint data update during the test run, turn on the Update DBTable elements option:

    1. Select Tools | Options from TestComplete’s main menu. This will open the Options dialog.
    2. Select the Engines | Stores category.
    3. Select Update DBTable elements.
    4. Click OK to close the dialog.

    Now, when you run the test, the database checkpoint will not perform verification. Instead, TestComplete will replace the stored data with the new data retrieved from the database.

     

    I would personally use scripting and create an ADO connection that checks just for that field on each run though. 

    • NT's avatar
      NT
      Contributor
      Hi cunderw, thanks for your aswer ! I decided to use ADO connection in a script but I still can't refresh the information in feield from the Database. here is the script can you help me to find what is wrong please ? function TestProc() { var Qry; var identifiant = KeywordTests.Cas1.Variables.IdentifiantVar1; var NewValue; // Create a query Qry = ADO.CreateADOQuery(); // Specify the connection string Qry.ConnectionString = "Provider=OraOLEDB.Oracle.1;Password=PW;Persist Security Info=True;User ID=User;Data Source=Database"; // Specify the SQL expression Qry.SQL = "SELECT etd_val_ident_execu_trait, etd_no_execu_xai, tdi_no_ident, pca_no_proje_calcu, etd_descr, etd_date_debut_execu, etd_date_fin_execu, std_statu_trait, etd_pourc_avanc FROM cpf_execu_trait_diffe WHERE tdi_no_ident = 3 AND TO_CHAR(etd_date_debut_execu, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD') ORDER BY etd_date_debut_execu DESC"; // Execute the query Qry.Open(); // Process results and Loop while the std_statu_trait field is not equal to "P" // (first it is equal to EC and after a certain time, it change to P // and this is when this happen that I would like to continue my test ) ... do // Here I try to refresh the field std_statu_trait to look if it has change to P // but never refresh the field it always keep the same value of the first read. NewValue = (Qry.FieldByName("std_statu_trait").Value); while (Qry.FieldByName("std_statu_trait").Value != "P"); { Log.Message(Qry.FieldByName("pca_no_proje_calcu").Value); Log.Message(Qry.FieldByName("std_statu_trait").Value + Qry.FieldByName("pca_no_proje_calcu").Value); } // Closes the query Log.Message("Statut égal P"); Log.Message(Qry.FieldByName("std_statu_trait").Value + Qry.FieldByName("pca_no_proje_calcu").Value); Qry.Close(); } Best regards,
      • cunderw's avatar
        cunderw
        Community Hero

        Without seeing your setup in person I would do something like this.

         

        At the end of  Test1 Run this script (obviously filling in the details).

         

        function checkStatut() {
          var dbConnection,
              record,
              statut;
          
          dbConnection = ADO.CreateADOConnection();
          dbConnection.ConnectionString = "connectionString"
          dbConnection.LoginPrompt = false;
          dbConnection.Open()
          
          record = dbConnection.Execute_("sql query");
          statut = record.Fields("Statut").Value;
          
          if (statut == "<P>")
        	KeywordTests.Test2.Run(); //assuming Test2 is a keyword test
        }