Page 1 of 1

Multiple Testing Environments - Database Connection Strings

Posted: Wed Mar 04, 2015 8:54 pm
by akc1207
Hello,

We have multiple environments in which automated testing is taking place (Dev, QA, Training) and so I have been maintaining the same test suite on each, as well as adding it to any new environments that it's not on yet. Each uses it's own database (SDEVSQL, SQASQL, STRAINSQL) and so this makes using and updating the same test suite in each environment much more difficult due to different connection strings.

This is an issue because the test suite covers multiple applications and is very large, complex, and constantly growing. Because of this, any time an addition to the suite is made (or in the case the whole test suite needs copied to the new environment), it can become a huge pain to change everything over to point to the right database, as there are a lot of SQL connectors.

My question is this: Is there a way that I can use the exact same test suite in each environment, but just set a flag or variable before executing that contains the name of the relevant database so that it can be used in the connection string for all the sql data connectors in the suite?

Or, is there simply another way to copy the whole test suite over and easily change all of these connection strings without having to manually go through every SQL connector and change it in the settings?

Thanks!

Re: Multiple Testing Environments - Database Connection Strings

Posted: Fri Mar 06, 2015 1:32 pm
by Support Team
Hello akc1207,

I am afraid that I cannot provide a one-click solution for your problem, but in order to set the connection string you can use the following code snippet.
DataCache dataCaches  = DataSources.Get("SQLConnectionString");
var conn = dataCaches.Connector as SqlDataConnector;
conn.ConnectionString = "Your New Connection String!";
Please keep in mind that you have to put this code before the test case with the specific SQL data source.
TestSuite.png
Regards,
Bernhard

Re: Multiple Testing Environments - Database Connection Strings

Posted: Fri Mar 06, 2015 8:57 pm
by akc1207
Hi Bernhard,

Thanks for the response! I gave this a try but am not able to see it work correctly yet.

I have a similar structure to your example TestSuite, and "TestCase1" has a SQLDataSource set up that is configured in the Manage Data Source menu to be connected to the "DevSQL" database. I have the ChangeConnectionString code module setting the connection string to the "TrainSQL" database for the Data Source. However, when I run this, it still pulls data from the "DevSQL" database. Am I missing a step here?

This is what I've added inside the code module, where dataSource is bound to a global variable "TrainSQL":

Code: Select all

string _dataSource = "";
[TestVariable("C65EBCEE-9877-4DAC-AE45-E6D437E350C2")]       
public string dataSource  
{  
	get { return _dataSource; }  
	set { _dataSource = value; }  
} 

public void ConnectionString(string dataSource)
{
	
	string connString = "\"Data Source=" + dataSource + ";Initial Catalog=Laboratory1;Integrated Security=SSPI;\"";
	
	DataCache dataCaches  = DataSources.Get("SQLConnectionString");
	var conn = dataCaches.Connector as SqlDataConnector;
	conn.ConnectionString = connString;
}
The Ranorex Report verifies that $dataSource = 'TrainSQL'

Re: Multiple Testing Environments - Database Connection Strings

Posted: Mon Mar 09, 2015 6:25 pm
by Support Team
Hi akc1207,

Your code seems to be OK. I am not exactly sure what the problem is, but I would try to create a code module only containing the change of the connection string and place it before the test case where the SQL data connector is added.
If this doesn't work it would be cool if I could take a look at your project.
Maybe you can attach it to your next post or send it to [email protected].

Regards,
Bernhard