Connecting to QC
In previous section, the code mentioned dealt with launching QTP using VBS script. Lets move on to see how we can connect the QTP that we have launched can be connected to Quality center.
We shall check if by any chance QTP is already launched( previous section code) and also already connected to QC
Below lines get the status whether QC connection already exist
Dim QCConnectStatus
QCConnectStatus = appQTP.TDConnection.IsConnected 'Check connection Status
If not connected then we shall connect. The QC_SERVER etc are all the constants values that are specific to your Quality center settings/location.
If QCConnectStatus = True then 'Connect if not connected
appQTP.TDconnection.Connect QC_SERVER_URL,QC_DOMAIN,_
QC_PROJECT,QC_USERNAME,QC_PASSWORD,False
If Err.number <> 0 Then 'Report Error, if any
strErrMsg = "Error occured while connecting to QC: " & vbNewLine & _
Err.Description
wscript.echo strErrMsg
End If
End if
Lets shall explore the method(function) TDConnection.Connect more. Below are the methods and properties this object returns
TDConnection Object
Methods
Connect | Connects QuickTest to the Quality Center project. |
Disconnect | Disconnects QuickTest from the Quality Center project. |
Properties
Domain | The Quality Center domain to which QuickTest is currently connected. |
IsConnected | Indicates whether QuickTest is currently connected to Quality Center. |
Project | The Quality Center project to which QuickTest is currently connected. |
Server | The Quality Center server to which QuickTest is currently connected. |
SupportVersionControl | Indicates whether the Quality Center server to which QuickTest is connected supports version control. |
TDOTA | Returns a TDOTA object, which exposes the Quality Center API and provides full interaction with Quality Center. |
User | The user that is currently connected to Quality Center. |
Connected method requires following values and below is the syntax
object.Connect ServerURL, DomainName, ProjectName, UserName, Password, EncryptedTrueorFalse
Opening the Test
After connecting to QC, say we got XXB test located in the path Subject/XXA/. Then the test path is
'Subject/XXA/XXB'
To open this test from the QC, the application object appQTP has got a method Open. Below is the example
ScriptPath = "Subject/XXA/XXB"
appQTP.open ScriptPath , True
'#####object.Open TestPath, [OpenInReadOnlyMode], [SaveCurrent]
make QTP visible
appQTP.visible=True
Okkay! So we are here, learnt launching QTP, and connecting to QC. Well to make a VBS script to run our test batches, its bit more long way to go. So lets see anything useful script we can create with till whats been blogged. Lets shall create a vbs file and run in it from command window to open the QC script. ( This script may become very useful if you have slow QC connection, as to navigate to script path will take considerable amount of time)
So my command line would be
wscript.exe OpenQCscript.VBS "[QualityCenter] Subject/XXA/XXB"
In Above command, 'wscript.exe' is the command application that can be used to invoke VBS file. It may come default with windows. OpenQCscript.VBS is the VBS file which will have the code which we have discussed till now. (VBS file is normal text pad file with VBscript and extenstion .vbs)
"[QualityCenter] Subject/XXA/XXB" is the scriptpath which i want to open. This is passed as arguments to VBS code.
Below two lines creates arguement object and echo each of the argument on to command window
Set ObjArgs = wscript.arguments
For x = 0 to ObjArgs.Count -1
wscript.echo ObjArgs(x)
next
If ObjArgs.Count > 1 then
wscript.exho "you have entered more than one script or the path is with spaces and not in quoted strings"
else
Set appQTP=CreateObject("QuickTest.Application")
If appQTP.launched <> True then 'Launch QTP application
appQTP.launch
If Err.number <> 0 Then
strErrMsg = "Error occured while Attempting to launch QTP" _ &vbNewLine & Err.Description
wscript.echo strErrMsg
End If
End if
ScriptPath = ObjArgs(0) ' First arguement
appQTP.open ScriptPath , True
appQTP.visible=True
end if
Interesting blog. Its very helpful.
ReplyDeleteNice one... VBscript information is very good...
ReplyDelete