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

To view or not the test results in UFT

Once a test is executed in QTP/UFT, test results are displayed. UFT provides us the option to view the test results once the test execution completes. Follow following steps for the same.
  • Navigate to Options>General.
  • There is checkbox "View results when run session ends". In case the checkbox is checked, UFT results are launched automatically once the test execution completes. In case not checked, the results are not launched automatically once execution completes.


viewrunresults

Sorting excel data multiple times based on column Name using VBScript


''Input Information - Workbook file Name with path
''WorkSheet Name
'' Provide the sort criteria based on which data needs to be filtered seperated by |

WorkBookFile = "C:\\testing.xls"
SheetName = "testing"
MultipleSortCriteria = "TestName|TestClass|TestPath"
'' Define the constants to be used in the script
  Const xlYes = 1
  Const xlAscending = 1
  Const xlDescending = 2
  Set oXL = CreateObject("Excel.Application")
  Set oWB = oXL.WorkBooks.Open(WorkBookFile)
  Set oWS = oWB.Worksheets(SheetName)  
  Set oRnge = oWS.UsedRange
  ColCnt = oRnge.columns.count
  '' Create an array based on the sort criteria provided 
  aSrtCriteria = split(MultipleSortCriteria,"|")
  For i = ubound(aSrtCriteria) to 0 step -1
  ''Loop the times data needs to be sorted
   For j = 1 to ColCount step 1
    
    If (oWS.cells(1,j).value =aSrtCriteria(i)) Then
     '' Sort the data based on the column name
     Set oRngeSrt = oXL.Range(Chr(asc("A")- 1+j) & "1")
     oRnge.Sort oRngeSrt, xlDescending, , , , , , xlYes 
     oWB.save
      Exit For
    End If    
   Next
  Next
   oWB.Close
   oXL.Quit
   Set oWB = Nothing
   Set oXL = Nothing
 

VBScript Code to close the IE browsers and Internet Explorer not responding window


  • VBScript Code to close the IE browsers and Internet Explorer not responding window

Set WShell = CreateObject("WScript.Shell")
''This will close all the instances of task iexplore.exe.
''Parameter /f kills the process forcefully
WShell.Exec("taskkill /fi ""imagename eq iexplore.exe"" /f")
WScript.Sleep 100
''At time Internet explorer is not responding error is displayed
''The task has window title as internet explorer not responding.
''We can close the task based on window title with regular expression as Internet *
WShell.Exec("taskkill /fi ""WINDOWTITLE eq Internet*"" /f")
WScript.Sleep 100
''Once the window is closed, another window appear with similar title
'' which needs to be closed
WShell.Exec("taskkill /fi ""WINDOWTITLE eq Internet*"" /f")

  • VBScript Code to save the list of running tasks and save it in file abc.txt


''Below command will return the service for the process and save it in file abc.txt
  Set WShell = CreateObject("WScript.Shell")
''This will close all the instances of task iexplore.exe.
''Parameter /f kills the process forcefully
WShell.Exec("tasklist /fi /svc>test.txt")

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

VBA Code- Extracting Database data into excel sheet using macro

Code to read the data from database and writing data in excel file using VB Macro and VBA.



'''' Naming the sub as auto_open will trigger the sub automatically on opening the file.
'''' We can create a sub with different name and assign macro to a control in the excel
''''file 
Sub auto_open()
'''' define the connection string to connect to the database, it can be a dsn created,
'''' or connection string to create to the database. Please refer connectionstrings.com
'''' to connect to different database using connection string.
connStr = "dsn=testthedb''
'''' Query to fetch data from the database
strGetEmployeeDetails = "select * from employee order by UserName asc;"
''''Provide reference of sheet to add data to in the current workbook. We can add a
''''sheet in excel, or refer to an external excel file/Sheet using excel.application.
''''In this example, Sheet Employee_Details exist in the current excel file
Set worksht = ThisWorkbook.Sheets("Employee_Details")
''''--------------------------
'''' Create database connection
   Set Conn = CreateObject("ADODB.Connection")
   Set rset = CreateObject("ADODB.Recordset")
   Conn.Open connStr
   rset.Open strGetEmployeeDetails, Conn, adOpenStatic

''''The recordset is stored in rset.
''''The first row of data is the column details of the query results
''''and is added in the results header

For i = 0 To rset.Fields.Count - 1
worksht.Cells(2, i + 2) = rset.Fields(i).Name
Next i

''''Copy the recorset data into excel file starting at row 3 and column 2
worksht.Cells(3, 2).CopyFromRecordset rset
rset.Close
Set rset = Nothing
ThisWorkbook.Save
Conn.Close
Set Conn = Nothing
End Sub

VBA Code: How to auto trigger operation on opening or closing an excel file

Problem : We need to perform or auto-trigger some operation while opening or closing an excel file. There may be operations required by excel user like connecting to database and auto populating the data from database  on opening the excel file and generating pivot tables and charts automatically based on database data. Similarly it can be any other event that user want to perform on opening excel file(saved in macro-enabled xlsm file format)


How to create a module in excel VBA?


Open the VBA editor by clicking Alt + F11 or go to Developer tab and click on Visual basic. Below image shows how to create a sub or function in VBA. Following are the steps for creating a sub or function in VBA:

1. Click on Developer

2. Click on Visual basic icon. (The above two steps can be achieved by clicking on Alt + F11.

3. In the workbook, add new module.

4. In the module, add sub as shown below.


Adding a sub in visual basic



How to create a sub that will be auto-triggered on opening the excel file?


Create a sub with name as auto_open as shown in the code below. Try writing a small code as shown below which will display a message box when the excel file opens.


 Sub auto_open()  
   MsgBox "Show message while opening the excel file"  
 End Sub  

How to create a sub that will be auto-triggered on closing the excel file?


Create a sub with name as auto_close as shown in the code below. Try writing a small code as shown below which will display a message box when the excel file closes.

 Sub auto_close()  
   MsgBox "Show message while closing the excel file"  
 End Sub  

Save the excel file in .xlsm format. 


Mindmap for Test Strategy

A test strategy acts as an outline document that describes the testing approach in the software development cycle. It is created to inform different stakeholders including project managers, testers, and developers about some key issues in the testing process.

A test strategy can be defined at organisation level or project level. If described at organisation level, the strategy is implemented in the projects in the organisation. Test Strategy document is not updated often and defines standards for testing activities and processes.