Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Tuesday, September 9, 2014

Closing of Browsers All Browsers ExceptQC/ALM Except Last Browser Except First Browser

'##################################
'Close All browsers
'##################################
'Method 1
'***************************************************
'Call Function
Call CloseAllBrowsers("IE")

'***************************************************
'Logic Explanation
'SystemUtil.Closeprocessbyname closes specific process by name
Function CloseAllBrowsers(oBrName)
 ' Close the specific/all browsers
 Select Case ucase(oBrName)

  Case "IE"
  'Close IE
   SystemUtil.CloseProcessByName "iexplore.exe"
  Case "FF"
  'Close FF
   SystemUtil.CloseProcessByName "firefox.exe"
  Case "CHROME"
  'Close CHROME
   SystemUtil.CloseProcessByName "chrome.exe"
  Case "ALL"
  'Close All Browsers
   SystemUtil.CloseProcessByName "iexplore.exe"
   SystemUtil.CloseProcessByName "firefox.exe"
   SystemUtil.CloseProcessByName "chrome.exe"

 End Select

End Function
'***************************************************
'Method 2
'***************************************************
'Logic Explanation
'Desktop is a built in object
'ChildObjects is a method to get child objects based on description provided in description object
'When we give "Micclass" as browser in description object, all browsers in desktop will be returned
'We for loop from "0"  to Count-1 because the Object Indexing starts from "0"
'We will close each and every browser with for loop and index

Function CloseAllBrowsers()
   'Declare Variables
 Dim oBrDes
 Dim oBrObjList
 Dim objIndex

 'Create Description Object with Browser class
 Set oBrDes=Description.Create
 oBrDes.Add "micclass","Browser"

 'Get Browser Objects from Desktop
 Set oBrObjList=Desktop.ChildObjects(oBrDes)

 'Use For Loop to close each browser
 'Use Count-1 because Object Indexing starts from "0"
 For objIndex=0 to oBrObjList.count-1
  'Close the Browser
  oBrObjList(objIndex).close
 Next

 'Release Variables
 Set oBrObjList=Nothing
 Set oBrDes=Nothing
End Function

'##################################
'Close All browsers except Alm/Qc
'##################################
'Logic Explanation
'Desktop is a built in object
'ChildObjects is a method to get child objects based on description provided in description object
'When we give "Micclass" as browser in description object, all browsers in desktop will be returned
'We will check the the title before closing every browser with for loop and index
'We for loop from "0"  to Count-1 because the Object Indexing starts from "0"
'If title is "Quality Center" or "ALM" we will not close it
Function CloseAllBrowsersExceptQC()
 'Declare Variables
 Dim oBrDes
 Dim oBrObjList
 Dim objIndex

 'Create Description Object with Browser class
 Set oBrDes=Description.Create
 oBrDes.Add "micclass","Browser"

 'Get Browser Objects from Desktop
 Set oBrObjList=Desktop.ChildObjects(oBrDes)

 'Use For Loop to close each browser
 'Use Count-1 because Object Indexing starts from "0"
 For objIndex=0 to oBrObjList.count-1
  'Verify the name of the browser is "Quality Center" or "ALM"
  If lcase(oBrObjList(objIndex).GetROproperty("name"))<>"mercury quality center" then
   'Close the Browser
            oBrObjList(objIndex).close
   Exit For
  End If
 Next

 'Release Variables
 Set oBrObjList=Nothing
 Set oBrDes=Nothing
End Function

'##################################
'Close All browsers except last opened browser
'##################################
'Logic Explanation
'Desktop is a built in object
'ChildObjects is a method to get child objects based on description provided in description object
'When we give "Micclass" as browser in description object, all browsers in desktop will be returned
'We for loop from "1"  to Count-1 because the in this script we will not work with object indexing
'We will get the count of number of browsers and write a FOR loop with Count-1 times 
'because we should close all browsers except one
'Each time we have to verify "0" creationtime browser exist and if exist close it
'We will repeat this Count-1 times
'The For Loop gets exit when the last browser creationtime becomes "0"
Function CloseAllBrowsersExceptLastBrowser()

 'Declare Variables
 Dim oBrDes
 Dim oBrObjList
 Dim iCounter

 'Create Description Object with Browser class
 Set oBrDes=Description.Create
 oBrDes.Add "micclass","Browser"

 'Get Browser Objects from Desktop
 Set oBrObjList=Desktop.ChildObjects(oBrDes)

 'Use For Loop to close each browser
 'Use Count-1 because we should close all browsers except one
 For iCounter=1 to oBrObjList.count-1
  'Close the first browser each time by checking creationtime "0"
  If Browser("creationtime:=0").Exist Then
   'Close Browser
            oBrObjList("creationtime:=0").close
  End If
 Next

 'Release Variables
 Set oBrObjList=Nothing
 Set oBrDes=Nothing
End Function

'##################################
'Close All browsers except First opened browser
'##################################
'Logic Explanation
'Desktop is a built in object
'ChildObjects is a method to get child objects based on description provided in description object
'When we give "Micclass" as browser in description object, all browsers in desktop will be returned
'We for loop from "1"  to Count-1 because the in this script we will not work with object indexing
'We will get the count of number of browsers and write a FOR loop with Count-1 times 
'because we should close all browsers except one
'Each time we have to verify "1" creationtime browser exist and if exist close it
'We will repeat this Count-1 times
'The For Loop gets exit when there no extra browsers

Function CloseAllBrowsersExceptLastBrowser()

 'Declare Variables
 Dim oBrDes
 Dim oBrObjList
 Dim iCounter

 'Create Description Object with Browser class
 Set oBrDes=Description.Create
 oBrDes.Add "micclass","Browser"

 ' Get Browser Objects from Desktop
 Set oBrObjList=Desktop.ChildObjects(oBrDes)

 'Use For Loop to close each browser
 'Use Count-1 because we should close all browsers except one
 For iCounter=1 to oBrObjList.count-1
  'Close the second browser each time by checking creationtime "1"
  If Browser("creationtime:=1").Exist Then
   'Close Browser
            oBrObjList("creationtime:=1").close
  End If
 Next

 'Release Variables
 Set oBrObjList=Nothing
 Set oBrDes=Nothing
End Function

No comments :

Post a Comment