Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

ReConnecting to Remote sessions using group policy edit

In QTP/UFT automation suite execution,we may require to connect remotely to multiple machines through remote desktop connection for monitoring test execution, We may face issue in remote connection being disconnected due to network issues/remote sessions. 


ReConnecting to Remote sessions using group policy edit
To allow smooth test execution, we should reconnect to the remote sessions in case of any network disconnect. In this post, I will share what we can do to reconnect remote connection in case of session disconnect due to network issues and failures.

  • Using experience in Remote Desktop Connection

    • Go to Run>mstsc
    • In Remote Desktop connection window, Go to Experience Panel.
    • Select checkbox "Reconnect if the connection is dropped"
By default, a maximum  of twenty reconnection attempts are made at five second intervals.


  • Defining Group policy for Remote Desktop connection

    • Navigate to group policy for the machine

      • Navigate to run> gpedit.msc
      • Local group Policy editor Window is displayed.
      • Click on Administrative Templates\Windows Components\Remote desktop Services\Remote Desktop Session Host\Connections
ReConnecting to Remote sessions using group policy edit

  • Policy Settings

ReConnecting to Remote sessions using group policy edit

    • Automatic Reconnection- If policy setting is enabled, automatic reconnection is attempted for all clients running Remote Desktop Connection whenever their network connection is lost.
    • Configure keep-alive connection interval - This policy setting allows you to enter a keep-alive interval to ensure that the session state on the RD Session Host server is consistent with the client state. If you enable this policy setting, you must enter a keep-alive interval. The keep-alive interval determines how often, in minutes, the server checks the session state. The range of values you can enter is 1 to 999,999.

Code to close multiple browsers except Quality Center/ALM in UFT/QTP?

Below Code shows how to close all browsers except browser based on the title of the browser in UFT / QTP.


Function CloseAllOpenbrowsersExcept(browsertitle)
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
''Get all browsers open 
Set oBrowserLst= Desktop.ChildObjects(oBrowser)
For i=0 to oBrowserLst.count-1  
'Verify the title of the browser and close the browser if it does not the title passed
'in the function
  If InStr(oBrowserLst(i).GetROProperty("title"), browsertitle) = 0 Then
    oBrowserLst(i).close  
  End If  
Next 
Set oBrowser = nothing
Set oBrowser = nothing
End Function


Similarly we can tweak the above code to close only a particular browser as shown below:


Function CloseOpenbrowserWithTitle(browsertitle)
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
''Get all browsers open 
Set oBrowserLst= Desktop.ChildObjects(oBrowser)
For i=0 to oBrowserLst.count-1  
'Verify the title of the browser and close the browser if it does not the title passed
'in the function
  If InStr(oBrowserLst(i).GetROProperty("title"), browsertitle) <> 0 Then
    oBrowserLst(i).close  
  End If  
Next 
Set oBrowser = nothing
Set oBrowser = nothing
End Function


Similarly we can close all browsers by removing the condition to check for title in the above code.


Function CloseAllOpenbrowsers()
Set oBrowser = Description.Create
oBrowser("micclass").Value = "Browser"
''Get all browsers open 
Set oBrowserLst= Desktop.ChildObjects(oBrowser)
For i=0 to oBrowserLst.count-1  
'Verify the title of the browser and close the browser if it does not the title passed
'in the function
      oBrowserLst(i).close  
Next 
Set oBrowser = nothing
Set oBrowser = nothing
End Function

Solution - ActiveX component can't create object: 'TDApiOle80.TDConnection'

We can connect to ALM using 'TDApiOle80.TDConnection' object in VBscript as shown below:



Function CreateALMConnection(uRLALM,strUserName,strPassword,strDomain, strProject)
 Set objALMConnection = CreateObject("TDApiOle80.TDConnection")
        objQCConnection.InitConnectionEx uRLALM
        objQCConnection.Login strUserName, strPassword
        objQCConnection.Connect strDomain, strProject
  
  ''/* Write the required code for transaction with 
               '' ALM once the connection is created
   
  objQCConnection.Disconnect            
        objQCConnection.Logout
        objQCConnection.ReleaseConnection
        Set objQCConnection = Nothing
End Function 

Some of the useful code for interacting with ALM from VBScript can be found at below location:


Copying files from ALM to local machine


While running the script in 64 bit machine, error message 'ActiveX component can't create object: 'TDApiOle80.TDConnection' is displayed. In case you encounter such error, you can run the script from SysWow64 location in Windows as : 


C:\Windows\SysWOW64\cscript.exe scriptfilewithPath.vbs


From cscript.exe, the script will run successfully