Saturday 17 March 2018

Broken Links and any Error links check from the web page with VB Script / UFT / QTP

Some times our customers may requests us to check for links which are broken from the web pages. This might be from the production sites or from the any of the web home page in pre-production sites.

Following code snippet can be used as quick solution to fulfill our requirement.

''#########################################################################
'' Use this code to verify all links are working fine in a already opened web page
''#########################################################################
On Error Resume Next
Set objBrowser = Description.Create
objBrowser("name").Value = "XXXXXXX"
objBrowser("CreationTime").Value = 0
Set objPage = Description.Create
objPage("title").Value = "XXXXX"

Set objLink = Description.Create
objLink("micclass").value = "Link"
objLink("html tag").value =  "A"

Set objBP = Browser(objBrowser).Page(objPage)

Set colLinkObjects = objBP.ChildObjects(objLink)

'Display count of all links

'Msgbox colLinkObjects.Count

inputFilesPath = "D:\Sample\WebLinksCheck.xlsx"
strSheetName = "Sheet1"

For i=2 to colLinkObjects.Count

    strLinkURL =  colLinkObjects(i).GetROProperty("url")
    strLinkName = colLinkObjects(i).GetROProperty("Name")
    ExportData2ExcelFile inputFilesPath,strSheetName,i,1,strLinkName
    ExportData2ExcelFile inputFilesPath,strSheetName,i,2,strLinkURL

    strVerifyMsg = VerifyLinksBroken(strLinkURL)
    ExportData2ExcelFile inputFilesPath,strSheetName,i,3,strVerifyMsg

Next

On Error GoTo 0

'=======================================================================
'Function: ExportData2ExcelFile()
' Description: Exporting runtime value to excel file
'Input: 
' =======================================================================

Public Function ExportData2ExcelFile(inputFilesPath,strSheetName,ColName,intRowNum,strValue)

  On Error Resume Next
'    inputFilesPath = Environment.Value("DataPath")

Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Visible = False
Set objWorkbook = ExcelObj.Workbooks.Open(inputFilesPath)
Set worksheet = objWorkbook.WorkSheets(strSheetName)

worksheet.cells(ColName,intRowNum).value  = strValue

objWorkbook.Save
objWorkbook.Close
ExcelObj.Application.Quit
Set objWorkbook = Nothing
Set ExcelObj = Nothing

On Error GoTo 0
End Function



Public Function VerifyLinksBroken(strURL)
On Error Resume Next

  'Create a WinHTTP Request using the link's URL
  Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
  objWinHTTP.Open "GET", strURL, False
  objWinHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"

  'Send the Request to the Server and capture the response
  objWinHTTP.Send
  iReturnVal = objWinHTTP.Status
  strErrorMsg = objWinHTTP.StatusText

  'Find out if the Link exists or is broken
  If iReturnVal = 200 Then
    strMsg = "Link - " & strURL & " Exists"
  ElseIf iReturnVal = 404 Then
    strMsg =  "Link - " & strURL & " is Broken with 404 error"
  Else
    strMsg =  "Error Code - " & iReturnVal & ":"&strErrorMsg&": Problem with this page"
  End If

  Set objWinHTTP = Nothing

On Error GoTo 0
VerifyLinksBroken = strMsg
End Function


Thursday 8 March 2018

Micro Focus UFT certification exam details

After HPE is merged in Micro Focus, it is been stopped UFT certification for a few days and now Micro Focus has opened the gates again for UFT certification.

Following are the details to appear for exam
Link to register: https://microfocus.viewcentral.com/events/cust/catalog.aspx?cid=microfocus&pid=1&lid=7&bu_id=12&cat1_id=150,151,149,124
Certification Name: Unified Functional Testing v12.5 (ASP)
Exam ID: UFT120-125-ASP-Exam
Price: 200 USD
Duration: 150 Mins
Who can appear : Software Testers, DevOps Team Members, Quality Assurance Leads
UFT software version: UFT 12.5
Number of questions: 50
Passing score: 70%

Useful information:
Each question has a time duration of 3 minutes to be attempted by the student, failure to mark a response within the stipulated time will move the student to the next question on the block.
This is an online exam, For Security reasons questions once skipped or submitted cannot be reattempted.
Test results consist of a percentage score for each question and an overall percentage score for the test. Upon passing the exam learners will be emailed a soft copy of the Certificate. Micro Focus do not provide a detailed itemized performance report to the learners.

Recommended Syllabus:

Section
Objectives
Section 1. Articulate base UFT Concepts

Identify functionalities and benefits provided by UFT
• Identify supported environments and supported technologies

Section 2.Identify and describe new features in UFT 12.5

Describe the changes in the installation process for V12.5
• Identify functional testing principles and the benefits of automated testing

Section 3. API testing with UFT

Identify standard activities in UFT that test common application processes
• Describe how to build a simple test using standard API activities

Section 4. Testing Web Services

• Describe how to build a Web Service Test
Describe how to integrate data in a Web Service test

Section 5. Using Parameters

• Identify and use different parameters types
Evaluate test results for iterative tests

Section 6. Running Tests

Identify enhancements to the Run Sessions pane
• Describe how to use the command-line syntax for running API tests
• Identify actions in GUI Testing
• Identify action types
• Identify calls to existing actions and copies of action

Saturday 3 March 2018

ALM project - field values update - easiest option

When you are working with ALM as administrator or project user,  you might have come across some challenges to upgrade any of the field values in bulk mode.

Example: updating test cases module/stream from one project

If we have few values then it would be easier to update manually by identifying the specific cases, but when you have massive cases then updating all values would be really tedious and time consuming.

If you have ALM DB access then simple way to update values is, connect to DB directly and fire SQL queries and commit the changes.

following is the one of the case how we can run update data by firing sql query

Prerequisite: we have to first connect to Project schema from DB client.


UPDATE ALM_DB.TEST
SET TS_USER_16 = 'MANUAL'
WHERE TS_TEST_ID = 54176 And TS_USER_16 = 'No'



UPDATE ALM_DB.TEST
SET TS_USER_16 = 'AUTOMATED'
WHERE TS_TEST_ID = 54176 And TS_USER_16 = 'Yes'

I had really saved couple of hours of effort after following this approach.

VBScript or UFT code to connect database and extract/update data

Following code can be used to connect to database to perform select/update queries.

Prerequisites:
  1. Install DB client in the machine from where we are executing this piece of code
  2. Establish DSN(Data Source Name)

Logic how VBScript code connects to DB:
DB client and WSH engine creates the interfaces/platforms separately but to make the bridge between both, we should have DSN which works as communication channel to perform the transactions.

strServerName= “abcd.com”
strDBName= “database”
strDBUserName="DBUserName"
strDBPWD= “DBPWD"
strSQL=  "Select * from employee "
If rc = micPass Then rc = DB_Execute_Query(strSQL,strServerName,strDBName,strDBUserName,strDBPWD)


'*******************************************************************************
'Function Name    : DB_Connection
'Description      : Function to establish the connection to database
'Input Parameters : strDataBaseUser,strDBPassword,strDataBaseName
'Output Parameters: None
'Createb By: Govardhan
'********************************************************************************


Public Function DB_Connection(strServerName,strDBName,strDBUserName,strDBPWD)
On Error Resume Next

Set Conn = CreateObject ("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
''' 'Create the string which is the command for connection
'''' strCon="Driver={PostgreSQL ANSI};Server=abc.com;Port=5432;Database=database;UID=server;PWD=server;"

strCon="Driver={PostgreSQL ANSI};Server="&strServerName&";Port=5432;Database="&strDBName&";UID="&strDBUserName&";PWD="&strDBPWD
Conn.ConnectionString = strCon
Conn.Open()
If Err.Number <> 0 then
rc = micFail
Reporter.ReportEvent rc,"Connect to database","Unable to connect to database due to following error," &_
vbcrlf & "Error Code: " & Err.Number &_
vbcrlf & "Error Description: " & Err.Description
Err.Clear
Else
rc = micPass
Reporter.ReportEvent rc,"Connect to database - "&strDBName &" - was successful","Connection successful"

Environment("DB_Connection_"&strDBName)= Conn
Environment("DB_Recordset_"&strDBName)= rs
End If
On Error GoTo 0
DB_Connection = rc
End Function

'*******************************************************************************
'Function Name    : DB_Execute_Query
'Description      : Function to execute a query and check if successfully executed or not
'Input Parameters : strSql,strDataBaseUser,strDBPassword,strDataBaseName
'Output Parameters: 0- Error,1 - Successful
'********************************************************************************

Public Function DB_Execute_Query(strSql, strServerName,strDBName,strDBUserName,strDBPWD)

On Error Resume Next

DB_Connection strServerName,strDBName,strDBUserName,strDBPWD
Set Conn = Environment("DB_Connection_"&strDBName)
Set rs = Environment("DB_Recordset_"&strDBName)  
   
Set rs = Conn.Execute (strSql)

If Err.Number <> 0 then

Reporter.ReportEvent micFail,"Query the database","Following error while querying the database," &_
vbcrlf & "Sql Statement: " & strSql &_
vbcrlf & "Error Code: " & Err.Number &_
vbcrlf & "Error Description: " & Err.Description
Err.Clear
rc  = micFail
DB_Execute_Query = rc
Else
rc = micPass
Reporter.ReportEvent micPass,  "Execute Sql Query","User should able to execute the sql query and the query is" & strSql ," Query Executed succefully"
DB_Execute_Query = rc
End If

'Close Connection and Recordset objects
DB_Close Conn,rs
On Error GoTo 0
DB_Execute_Query = rc
End Function

'*******************************************************************************
'Function Name    : DB_Close
'Description      : Function to disconnect the DB connection
'Input Parameters : strDataBaseName,RecordSet 
'Output Parameters: None
'********************************************************************************

Public Function DB_Close(strConnection,StrRecordSet)
On Error Resume Next

Set StrRecordSet= nothing
strConnection.close
    Set strConnection = nothing

On Error GoTo 0

End Function