Quick test professional

QTP Tips QTP codes QTP Faqs and more

Close Opened Browsers Except QC

Dim intIndex
Set oDesc=Description.Create
While Browser(“micclass:=Browser”,”index:=”&intIndex).exist(0) and intIndex<Desktop.ChildObjects(oDesc).count
If instr(1, Browser("micclass:=Browser","index:="&intIndex).getRoProperty("name"),"Quality Center") = 0 Then
SystemUtil.CloseProcessByHwnd( Browser("micclass:=Browser","index:="&intIndex).getRoProperty("hwnd"))
End if


March 17, 2011 - Posted by | Browser Scripts, Descriptive programming, Descriptive Programming and Child Objetcs


  1. I have used code given below to identify all the child object of type ‘Links’
    in a perticuler web Page but

    In Line 3 i am getting genral error can you please let me know what is the solution for this error.

    Set desc=description.Create
    Set obj_link=Browser(“Creationtime:=0”).Page(“Title:=.*”).ChildObjects(desc)
    msgbox obj_link.count

    Whereas if i m runnung this script on my friends tool it works fine.I m not able to understand whats wrong in my tool.Please tell me the solution.

    Comment by Satnam | April 28, 2011 | Reply

  2. hi
    can you please explain the following code?
    Function CaptureToWord()
    sTscenarioPath = GetData(“ScreenshotPath”)&Environment(“TestName”)
    sWordFileName= sTscenarioPath&”\”&Environment(“TestName”)&”.doc”
    Dim sFileCapture()
    sFileCaptureLen = -1
    Const END_OF_DOC = 6
    Set fileSys = CreateObject(“Scripting.FileSystemObject”)
    Set sSubFiles=fileSys.GetFolder(sTscenarioPath).Files
    If sSubFiles.Count = 0 Then
    Set fileSys = Nothing
    Set sSubFiles = Nothing
    Exit Function
    End If
    Dim aResponsibility()
    Datatable.ImportSheet GetData(“FilePath”),Environment(“TestName”),Environment(“TestName”)
    iRowCount =datatable.GetSheet(Environment(“TestName”)).GetRowCount

    k = 0
    For iCountNo = 1 to iRowCount


    If trim(Datatable(“Testcase_Id”,Environment(“TestName”))) “” Then
    ReDim Preserve aResponsibility(k)
    ReDim Preserve aTCName(k)
    aResponsibility(k) = Trim(Datatable(“Responsibility”,Environment(“TestName”)))
    aTCName(k) = Trim(Datatable(“TestCase_Name”,Environment(“TestName”)))
    k = k+1
    End If
    If trim(Datatable(“Testcase_Id”,Environment(“TestName”))) = “” Then
    Exit For
    End If

    Set obj_MSWord = CreateObject(“Word.Application”)
    Set objDoc = obj_MSWord.Documents.Add()
    For Each iSubFiles in sSubFiles
    If Right(iSubFiles.Name,4) = “.png” Or Right(iSubFiles.Name,4) = “.PNG” Then
    ReDim Preserve sFileCapture (sFileCaptureLen+1)
    sFileCapture(UBound(sFileCapture)) = iSubFiles & fileSys.GetFile(iSubFiles).DateLastModified
    sFileCaptureLen = sFileCaptureLen +1
    End If
    For i = LBound(sFileCapture) To UBound(sFileCapture)-1
    min = i
    For j = (i + 1) to UBound(sFileCapture)
    if StrComp(Right(sFileCapture(j),20), Right(sFileCapture(min),20))=-1 Then
    min = j
    End If
    Temp = sFileCapture(i)
    sFileCapture(i) = sFileCapture(min)
    sFileCapture(min) = Temp

    For i = LBound(sFileCapture) To UBound(sFileCapture)
    strLWordFile = Split(sFileCapture(i),”\”)
    strDesc = Split(strLWordFile(4),”.png”)
    sLWordFile = strLWordFile(0) &”\” & strLWordFile(1) & “\” & strLWordFile(2) & “\” & strLWordFile(3) & “\” & strDesc(0) & “.png”
    ‘MsgBox strDesc(0)
    TC = Split(strDesc(0),”_TC”)
    iTC = GetNumberFromString(TC(1),0)
    tChar = Len(TC(1))
    iChar = Len(iTC)
    sActivity = Right(TC(1),tChar-iChar)
    eActivity = Replace(sActivity,”_”,” “)
    Set objSelection = obj_MSWord.Selection
    ‘objSelection.TypeText “Table”&i

    Set objRange = objSelection.Range
    objDoc.Tables.Add objRange, 5, 2
    Set objTable = objDoc.Tables(i)
    objTable.Range.Font.Size = 15
    objTable.Range.Style = “Table Contemporary”
    objTable.Cell(1, 1).Range.Text = “Scenario Id”
    objTable.Cell(2, 1).Range.Text = “Responsibility”
    objTable.Cell(3, 1).Range.Text = “Test Case Id”
    objTable.Cell(4, 1).Range.Text = “Test Case Name”
    objTable.Cell(5, 1).Range.Text = “Screen/Activity/Verification”
    objTable.Cell(1, 2).Range.Text = Environment(“TestName”)
    objTable.Cell(2, 2).Range.Text = aResponsibility(iTC-1)
    objTable.Cell(3, 2).Range.Text = “TC”&iTC
    objTable.Cell(4, 2).Range.Text = aTCName(iTC-1)
    objTable.Cell(5, 2).Range.Text = eActivity
    objSelection.EndKey END_OF_DOC
    objSelection.TypeText ” ”
    Set objTable = Nothing
    Set objRange = Nothing
    Set objSelection = Nothing

    ‘obj_MSWord.Selection.TypeText strDesc(0) &” ”

    Set obj_MSWord = Nothing
    Set objDoc = Nothing
    Set sSubFiles = Nothing
    Set fileSys = Nothing
    End Function

    Comment by Sathiya | April 29, 2011 | Reply

  3. Hi Mohan,

    I am trying to open QC in QTP. I am able to do that. I can open a File-Open dialog box using DotNetFactory.CreateInstance as you suggested. However I am not able to open the Quality Center path in that dialog box. Will you help?

    Comment by Bhakti | June 20, 2011 | Reply

  4. Function getcharcount(strchar,strsearch)
    Dim i
    For i=1 to len(strsearch)
    If mid(strsearch,i,1)=strchar Then
    End If
    msgbox getcharcount
    msgbox strchar
    End Function please give me qtp code to automate this


    Comment by mallikarjun | October 27, 2011 | Reply

  5. Hi to all, as I am in fact keen of reading this weblog’s post to be updated regularly. It carries pleasant information.

    Comment by abate of illinois | January 22, 2013 | Reply

  6. after writing the below script i m getting General Run Error.
    Can somebody suggest me the right answer.??

    Function FindObject(ObjectName)

    Set desc=description.Create
    For j=1 to datatable.GetSheet(“OR1”).GetRowCount

    If datatable(“name”,”OR1″)=ObjectName Then

    If datatable(“micclass”,”OR1″)” ” Then
    End If

    ‘ If datatable(“html id”,”OR1″)” ” Then
    ‘ desc(“micclass”).value=datatable(“html id”,”OR1″)
    ‘ End If

    If datatable(“class”,”OR1″)” ” Then
    End If

    Set obj=Browser(“creationtime:=0”).page(“title:=.*”).ChildObjects(desc)

    set FindObject=obj(0)

    End If

    End Function

    Comment by akhandesh | August 21, 2013 | Reply

  7. can any body tell me whats the problem in the above script..???

    Comment by akhandesh | August 21, 2013 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: