Forum Discussion
Not yet. If i want a variable to be available in other methods i assign it to Project variables and then retrieve it when needed. Likewise lets say i have a method which just establishes connection with the db, how can i use this db connection in other methods. I'm stuck here, since i cannot assign this to project variables.
- sriram_sig7 years agoContributor
The example which you provided me earlier helps to create db connection, but i also want to use this same connection in other methods
I'm not a python dev by any means but something like this I think is what you are looking for:
connectSting = "" AConnection = ADO.CreateADOConnection() def GetConnection(): if AConnection.Connected == False: Log.Message("Connecting") AConnection.ConnectionString = connectSting # Suppress the login dialog box AConnection.LoginPrompt = False AConnection.Open() elif AConnection.Connected == True: Log.Message("Connected") return AConnection def test(): connection = GetConnection() connection = GetConnection()
Then if you want to use that in other script units see: https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/python.html
- sriram_sig7 years agoContributor
Thank you. This is exactly what i was looking for.
- tristaanogre7 years agoEsteemed Contributor
Rather than a project variable, is there a way to make a variable declared in one Python unit available for others? In JavaScript, if you export a variable and then use the "requires" call in a subsequent unit, you can access that variable anywhere.
Alternatively, you could create a Script Extension whose sole purpose is to provide an ADO DB connection. that you can then access from anywhere.