Friday, September 18

VBScript - 2 . Connecting to QC/Open QC test

 This is in continuation of VBScript - 1 . Launching QTP

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,_
        If Err.number <> 0 Then    'Report Error, if any
            strErrMsg = "Error occured while connecting to QC: " & vbNewLine & _
            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
Connects QuickTest to the Quality Center project.
Disconnects QuickTest from the Quality Center project.
The Quality Center domain to which QuickTest is currently connected.
Indicates whether QuickTest is currently connected to Quality Center.
The Quality Center project to which QuickTest is currently connected.
The Quality Center server to which QuickTest is currently connected.
Indicates whether the Quality Center server to which QuickTest is connected supports version control.
Returns a TDOTA object, which exposes the Quality Center API and provides full interaction with Quality Center.
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

To open this test from the QC, the application object appQTP has got a method Open. Below is the example

ScriptPath  = "Subject/XXA/XXB"  ScriptPath , True

'#####object.Open TestPath, [OpenInReadOnlyMode], [SaveCurrent]

make QTP visible

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)


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"
   Set appQTP=CreateObject("QuickTest.Application")
   If appQTP.launched <> True then 'Launch QTP application

     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  ScriptPath , True

end if 


Related Posts Plugin for WordPress, Blogger...