Forum Discussion

progz's avatar
progz
Occasional Contributor
8 years ago
Solved

How do I send MySQL queries to a database within a test?

Hello everyone,

 

I am currently testing a POS software that works on the side with a MySQL 5.5 MyISAM engine type database. Within my project I have several tests that I can do. The program is working perfectly, but I would like to add (I think it is a called) a script to delete everything I did in the software that is kept in the database. How would I go about doing this? I'm too educated in software programming, but willing to learn the easy stuff. Basically I would want to do a simple MySQL query like "TRUNCATE TABLE tablename". But from my research it seems that I would need to use a programming language to do this. Also, I would need to insert the database connection information so this query could be performed. Can someone go into a little detail as to how I can do such a task in the Test complete application?

 

Lastly, I would want this to run at the end of a "test" with my project so I can constantly re-run the "test" within the project whenever I want to, without actually having to delete the mysql queries that were performed while using the application.

 

Thank you!

  • I'm assuming, to date, you've been using mainly Keyword Tests to create your project. 

    It is not impossible to do SQL queries and stuff in KeywordTests... but I find it cumbersome.  It feels much easier and intuitive to me to use, as you mention, "a programming language". 

    When you created your project, you selected a programming language.  Even though you aren't using it to write your tests, you've already taken that step.  

     

    There are some examples showing, briefly, how to do this... check out https://support.smartbear.com/viewarticle/18441/

     

    I also created a Script Extension some time back that does what you want...I don't have any documentation written up for it (yet) but, if you want to try it, you can download it at https://bitbucket.org/tristaanogre/tabledrivenframework/downloads/SQLUtilities.tcx and then just send me a private message for how to use it.

    But yes... to do a TRUNCATE TABLE you're going to want do something a bit more than just a keyword test.

     

     

     

     

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I'm assuming, to date, you've been using mainly Keyword Tests to create your project. 

    It is not impossible to do SQL queries and stuff in KeywordTests... but I find it cumbersome.  It feels much easier and intuitive to me to use, as you mention, "a programming language". 

    When you created your project, you selected a programming language.  Even though you aren't using it to write your tests, you've already taken that step.  

     

    There are some examples showing, briefly, how to do this... check out https://support.smartbear.com/viewarticle/18441/

     

    I also created a Script Extension some time back that does what you want...I don't have any documentation written up for it (yet) but, if you want to try it, you can download it at https://bitbucket.org/tristaanogre/tabledrivenframework/downloads/SQLUtilities.tcx and then just send me a private message for how to use it.

    But yes... to do a TRUNCATE TABLE you're going to want do something a bit more than just a keyword test.

     

     

     

     

    • progz's avatar
      progz
      Occasional Contributor

      Thank you for all the information you have posted. The thing is, I did see that url ( https://support.smartbear.com/viewarticle/18441/#_ga=1.58098088.346800190.1479231266 ) before posting this thread. The programming code that I select to start doing the 'recorded' test were with C++, which I did not see how that page. Because of that, I was not sure if I could still use the ones listed on the website. I did download the extension though and would love to learn how to use it. Will PM you after this post.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        The syntax for C++ is pretty similar to the JScript syntax posted on that page... so you should be able to work with that, at least for starters.

        I'll look for your PM.  It might not be until later this evening that I'll be able to dedicate time to it but I'll certainly do what I can.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Will do. I noticed last night that, right now, I assume an MS SQL database so I need to do a bit of work to make it a bit more universally useful.

    The trick about Script extensions though is that, if you change tcx to zip, you can get to the files so it is, if you can read code, kind of self documenting.

    I didn't get to make the necessary code changes last night since I was at my daughters orchestra concert... should get to it this evening.