Forum Discussion

augustine_uzokw_1's avatar
10 years ago

How to clean up DB record created during test run

can anyone help me out?  what is the best way to clean up DB records after test test run?



  • If your application has a Delete option, then just write a little script/keyword test to go back and delete the records you've created.  



    Another option is to have a backup with a copy of the database from before the test and then after the test is run, restore the backup automatically.  
  • In the initial question/answer, I thought we were talking about application data.  For instance, our application has a Create function for an Item, which adds a record to the database.  If we want to always create an Item with the same information in every run of our test, then at the end of the test, we use the Delete function to delete the item, which cleans up the database.  If we want to create an item and perform some other functions on it that then will no longer allow a delete, then if we want to start over, we have to restore a clean copy of the database before the test is run.  Unfortunately for us, that's a manual process right now.



    The Database Checkpoint operation is for comparing databases rather than updating one or the other, so I don't think that's what you want to use.  Can you give a more specific example of what you're trying to do?  I'm working with keyword tests too, so I can give it a try.
  • linda_marshall's avatar
    linda_marshall
    Occasional Contributor
    Re Marsha's response, but going off the cleaning up DB question slightly...



    Marsha, you say "If your application has a Delete option, then just write a little script/keyword test to go back and delete the records you've created".  To me this means that it's possible to write a keyword test to delete a database record. In this case, I assume it's also possible to update a database record.  I've tried using Database Checkpoint for this but can only update records in the stored table, not the actual database record.



    How would I update data on a database record using a Keyword Test?   I'm new to TestComplete and am sticking to using Keyword Tests to start.





  • linda_marshall's avatar
    linda_marshall
    Occasional Contributor
    Thanks for confirmation that Database checkpoint is purely for comparison, so I wasn't missing a trick. 



    This would be part of a set of data set up scripts that are being automated.  Apart from one item of data the application data can be updated throught he GUI, so no problem with keyword tests. At present one data item needs to be updated 'manually' through a SQL update (this is a step in the manual test script).  It would be nice to be able to include a script to update this item in the group of automated scripts.  



    So, basically, I want to access an Oracle database (which I can do from the Database Checkpoint) and update a table. 



  • jorgesimoes1983's avatar
    jorgesimoes1983
    Regular Contributor

    We created this function to executed SQL Querys, maybe it is useful for you.

    Example of usage:

     

    sqlQueryExecute(server, "update "+database+"table set table_name= 'something' where = 1")

     

    /**
     * @method sqlQueryExecute
     * @param {string} server IP
     * @param {string} query to execute
     */
    function sqlQueryExecute(server, query)
    {
      Log.Message("IF ODBC error... check your firewall for SQL Server port 1433 inbound/outbound");
     
      var ConnectionString = "DRIVER=SQL Server;SERVER="+ server +";UID=user;PWD=user";
     
      // Creates a new connection
      var ConnDB = ADO.CreateConnection();
      var adoRecSet = ADO.CreateRecordset();
      ConnDB.ConnectionString = ConnectionString;
      ConnDB.Open();
     
      // Opens a recordset
      ConnDB.Execute(query);
      Log.Checkpoint("QUERY EXECUTED")
      // Closes the connection  
      ConnDB.Close();
    }