Forum Discussion

JustinL22's avatar
JustinL22
Contributor
3 years ago

Switching database connections based on environment

Hi,

I currently have a suite of keyword tests that have been built up to run on a specific test environment e.g. Environment A. If I want to run these same tests across different environments I understand there are some updated required to the object mapping urls to allow this to work such as wildcarding out the test environment name.

 

However within some of the tests there are database check points that when originally set up require the database connection to be specified. If I change the environment they are run on e.g. Environment A to Environment B then the database query will be looking in the wrong location. Is there a way the database connection for the checkpoint can be switched based on the environment the test is run in?

 

Thanks 

3 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    I'm not sure how you have configured your database connection string, but it might be worth having a project variable which holds your database connection string. Without making changes to your actual project, you can pass your database connection string to your project variable using TestComplete Command Line, see /PSVar and /PrjVar.

     

    I've written my automation using scripts, and I use an ini file,

    I have the ability to change the environment, database, browser, username and password

    • JustinL22's avatar
      JustinL22
      Contributor

      How would you pass that project variable into the database table check point server name field though?

       

      When I set up a database checkpoint it requires me to enter the server name I want to run the query on so this corresponds to the environment I am running my test in. If I change environment I would need to change this server name on the database checkpoint so I'm not sure how I would go about adding a variable to be able to switch this. 

       

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    Ah, that might be tricky!

     

    The other alternative is, if you only have two environments, then use an if statement. For example in your keyword test,

     

    If EnvironmentA Then
      DBCheckpointA
    else if EnvironmentB Then
      DBCheckpointB

     

    Someone might be able to come up with a better way of doing this using keyword testing.

     

    See if Alternatives to Database Checkpoints is able to help