QTP and TestLink

Discuss test processes, standards, documentation, teams, criteria, test environments, etc.

Moderators: Amaradana, TurboPT, TL Developers

QTP and TestLink

Postby crazyhere » Mon Jun 14, 2010 1:39 pm

Hi all,

First, Apologies if this question is already posted. I am trying to evalaute TestLink so as to see if it can integrate well with QTP.
I have recently installed TestLink. I ahev logged in and created Users, Requirements, Test Plans, Test Cases etc.

Questions is:
1, How do we store QTP Test Cases in TestLink?
2, Can we run QTP Test Cases present in a C Drive and execute the same?
3, Do we need to Know anything about TestLink API before running?

I have executed QTP Test CAses from QC. QTP Test CAses can be stored in QC once you establish the connection. I am trying to see if there is anything similar.

Please be kind enough to explain to a novice TestLink User.

Thanks
Crazy
crazyhere
TestLink user
 
Posts: 1
Joined: Mon Jun 14, 2010 1:32 pm

Re: QTP and TestLink

Postby abrown2010 » Wed Jun 30, 2010 2:10 pm

Hello,

I've managed to integrate it very loosely. Firstly, you will not achieve the kind of integration Quality Center offers. What you can do is have TestLink be the master storage of execution results for test cases. Solution I have is to create test cases in TestLink, I note the TEST IDs (expose them by custom_config.php change), I copied these test ids into a column in Excel used by QTP to drive test cases. I have custom functions for reporting (basically writing the results to files for each test case and screenshots where required, no need for QTPs Reporter). I wrap around the test (runaction) functions that first create results file, then for the action / test write to a test results file on the server (happens to be TestLink server), now that we know the TEST IDs of test cases from TestLink this helps us to make an XML file ready for TestLink to import after execution. And within this XML we can add to the NOTES section of a test in TESTLINK providing the link to the results file and any other info (its too small a field to write lots of data too that's why we just send results to a file). You then import the XML to the test execution and you'll have results presented. The approach I used to persist info in QTP is write to Environment variable (created at runtime), could write large amounts of data to it. Its not perfect but does give visibility of test results in TestLink. Hope this helps, code provided but you'll need to read it few times to get the idea. Good luck...

Here's an snippet of code from the main driver script:

'loop round every iteration in the master spreadsheet
For i = 1 to vDriverRowCount

'create TestLink XML report file
Call fCreateResultsFile

'run the action that will perform the testing
vTestResult = RunAction(vAction, oneIteration, vTestRef)

'update the XML results file for TestLink
Call fUpdateResults(vTestCaseId, vTestResult)

DataTable.SetCurrentRow(i)

End If

DataTable.SetNextRow
Next

'close the XML results file for TestLink
Call fCloseResultsFile

Then within your callable Actions, you'll want to add exit statements where necessary i.e. ExitAction("f") maps to FAIL result, this returns to the main script value vTestResult. And at the end of the callable Action as the last statement, add this (it collects the calls to the custom reporter, everything was held in memory):

'outputs the ExitAction
Call fTestLinkResult

This writes the results to text file.

Here's the functions to create XML file and the functions to call to update it during execution:
'functions index
'- fUpdateResults: writes to XML results
'- fCreateResultsFile: creates / overwrites last XML file
'- fCloseResultsFile: finishes off the file and closes it with final tag
'- fTestConditionCount: counts the FAIL items, a singel fail within an action is a FAILED action
'- fTestLinkResult: outputs the final PASS / FAIL to the ExitAction statement
'- fCallTimeSeconds: gets the time taken for the test in seconds or minutes
'######################################################################################################################
'Function Name: fUpdateResults
'Date: 19/02/10
'Description: writes XML results file for TestLink
'arguments:
' vTestCaseId: The external TestLink Test Case ID, stored in the Master.XLS file
' vResult: The overall test case result p=passed, f=failed only, other statuses not used in this context
' vNotes: The notes to be added to the Test Case run
'######################################################################################################################

Function fUpdateResults(vTestCaseId, vResult)

Const ForAppending = 8

Dim fso
Dim file
Dim vFileName
Dim strTotals
Dim vTimeTaken

'Get end time for test and calculate differences
Environment.Value("vEndTime") = time
vTimeTaken = fCallTimeSeconds(Environment.Value("vStartTime"),Environment.Value("vEndTime"))

'Set variables
vTestLinkHttpPath = "http://lnvltestlink/testlink/qtp/"
vFolderName = "RUN_DATE_" & Replace(Date, "/", "_") & "/RESULTS"
vFileName = vTestCaseId &"_'" & Environment.Value("TestRef") & "_TIME_" & Replace(time, ":", "_") & ".txt"
strTotals = "TOTAL NUMBER OF PASSED: " & Environment.Value("vPass") & VBCrlf & "TOTAL NUMBER OF FAILED: " & Environment.Value("vFail") & VBCrlf & "TOTAL NUMBER OF WARNINGS: " & Environment("vWarning") & VBCrlf & vTimeTaken & VBCRlf

Set fso = CreateObject("Scripting.FileSystemObject")

'Create XML results entry for TestLink
Set file = fso.OpenTextFile(Environment("EnvResultsDir"), ForAppending, True)
file.WriteLine("<testcase external_id=""" & vTestCaseId & """>")
file.WriteLine("<result>" & vResult & "</result>")
file.WriteLine("<notes>" & vTestLinkHttpPath & vFolderName & "/" & vFileName & VBCrlf & VBCrlf)
file.WriteLine(strTotals & VBCrlf & "</notes>")
file.WriteLine("</testcase>")
file.Close

'Create folder for test case on TestLink if it doesn't exist
If Not (fso.FolderExists(Environment("EnvTestLinkResultsDir") & "RUN_DATE_" & Replace(Date, "/", "_"))) Then

Set file = fso.CreateFolder(Environment("EnvTestLinkResultsDir") & "RUN_DATE_" & Replace(Date, "/", "_"))

End If

'Create folder for test case on TestLink if it doesn't exist
If Not (fso.FolderExists(Environment("EnvTestLinkResultsDir") & vFolderName)) Then

Set file = fso.CreateFolder(Environment("EnvTestLinkResultsDir") & vFolderName)

End If

'Write to txt file
Set file = fso.OpenTextFile(Environment("EnvTestLinkResultsDir") & vFolderName & "\" & vFileName, ForAppending, True)
file.WriteLine(Environment.Value("EnvTLNotes"))
file.WriteLine strTotals
file.Close

'Reset Global TestLink variables
Environment.Value("EnvTLNotes") = ""
Environment.Value("vFail") = 0
Environment.Value("vPass") = 0
Environment.Value("vWarning")=0

End Function

'######################################################################################################################
'Function Name: fCreateResultsFile
'Date: 19/02/10
'Description: creates XML results file for TestLink
'######################################################################################################################

Function fCreateResultsFile

Dim fso
Dim file

'Reset Environment values, distortion from Driver Script
Environment.Value("vFail") = 0
Environment.Value("vPass") = 0

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(Environment("EnvResultsDir")) = "True" Then

Exit Function

End If

Set file = fso.CreateTextFile(Environment("EnvResultsDir"), True)
file.WriteLine("<results>")
file.Close

End Function

'######################################################################################################################
'Function Name: fCloseResultsFile
'Date: 19/02/10
'Description: closes the XML results file
'######################################################################################################################

Function fCloseResultsFile

Const ForAppending = 8

Dim fso
Dim file

Set fso = CreateObject("Scripting.FileSystemObject")

Set file = fso.OpenTextFile(Environment("EnvResultsDir"), ForAppending, True)
file.WriteLine("</results>")
file.Close

End Function

'######################################################################################################################
'Function Name: fTestConditionCount
'Date: 19/02/10
'Description: Counts the FAIL items, a singel fail within an action is a FAILED action
'######################################################################################################################

Function fTestConditionCount(vTest)

If vTest = "f" Then

Environment.Value("vFail") = Environment.Value("vFail") + 1

ElseIf vTest = "p" Then

Environment.Value("vPass") = Environment.Value("vPass") + 1

ElseIf vTest ="w" Then

'Initially let's block the test case so that attention is brought to it
Environment.Value("vWarning") = Environment.Value("vWarning") + 1

Else

'Do nothing

End If

End Function

'######################################################################################################################
'Function Name: fTestLinkResult
'Date: 19/02/10
'Description: Outputs the final PASS / FAIL to the ExitAction statement
'######################################################################################################################

Function fTestLinkResult

'result for TestLink
If Environment.Value("vFail") > 0 Then

'Fail the test
ExitAction("f")

ElseIf Environment.Value("vWarning") > 0 Then

'Block the test for WARNINGS
ExitAction("b")

Else

'Pass the test
ExitAction("p")

End If

End Function

'######################################################################################################################
'Function Name: fCallTimeSeconds
'Date: 19/02/10
'Description: Calculates time difference for the report
'######################################################################################################################


Function fCallTimeSeconds(vStartTime,vEndTime)

vStartHour = Hour(vStartTime)
vStartMin = Minute(vStartTime)
vStartSec = Second(vStartTime)
vEndHour = Hour(vEndTime)
vEndMin = Minute(vEndTime)
vEndSec = Second(vEndTime)
vStartingSeconds = (vStartSec + (vStartMin * 60) + ((vStartHour * 60)*60))
vEndingSeconds = (vEndSec + (vEndMin * 60) + ((vEndHour * 60)*60))

vRetTime = vEndingSeconds - vStartingSeconds
vRetMinutes = vRetTime

'Output as minutes rounded
If vRetTime >59 Then

fCallTimeSeconds = "EXECUTION TIME (IN MINS): " & Round( vRetMinutes / 60 ,0)

'Output as seconds
Else

fCallTimeSeconds = "EXECUTION TIME (IN SECS): " & vRetTime

End If

End Function



Here's the Reporter replacement (still references Reporter inside it for safety):
Public Function fReporterCheck(vInfo, vExpectedVal, vActualVal,vType,vCondition)

'Check if it is a conditional check or not
If vType = "MESSAGE" Then

If vCondition = "PASS" Then
Reporter.ReportEvent micPass, vInfo, ""
'Print "**PASS***. " & vInfo

'Add PASS event to TestLink variable
Environment.Value("EnvTLNotes") = Environment.Value("EnvTLNotes") & VBCrlf & "PASS " & vInfo & ". Time: " & time

Exit Function

ElseIf vCondition = "FAIL" Then
Reporter.ReportEvent micFail, vInfo, ""
'Print "**FAIL***. " & vInfo


'Add FAIL event to TestLink variable
Environment.Value("EnvTLNotes") = Environment.Value("EnvTLNotes") & VBCrlf & "FAIL " & vInfo & ". Time: " & time


Exit Function

ElseIf vCondition = "DONE" Then

Reporter.ReportEvent micDone, vInfo,""
'Print "**DONE***. " & vInfo

'Add FAIL event to TestLink variable
Environment.Value("EnvTLNotes") = Environment.Value("EnvTLNotes") & VBCrlf & "DONE " & vInfo & ". Time: " & time

Exit Function

ElseIf vCondition = "WARNING" Then

Reporter.ReportEvent micWarning, vInfo,""
'Print "**WARNING***. " & vInfo

'Add FAIL event to TestLink variable
Environment.Value("EnvTLNotes") = Environment.Value("EnvTLNotes") & VBCrlf & "WARNING " & vInfo & ". Time: " & time


Exit Function

Else

Reporter.ReportEvent micFail, "ERROR IN CAPTURING RESULTS SEE INPUT STRING", vInfo & " " & vExpectedVal & " " & vActualVal & " " & vType & " " & vCondition


End If

End If

'Check if the report is looking for a match
If vType = "MATCH" Then

'Checks Conditional input
If vExpectedVal = vActualVal Then
Reporter.ReportEvent micPass, vInfo, "Expected value = " & vExpectedVal & ". Actual value = " & vActualVal
Print "**PASS***. " & vInfo & ". Expected value = " & vExpectedVal & ". Actual value = " & vActualVal

'Add PASS event to TestLink variable
Environment.Value("EnvTLNotes") = Environment.Value("EnvTLNotes") & VBCrlf & "PASS " & vInfo & ". Expected = " & vExpectedVal & ". Actual = " & vActualVal & ". Time: " & time


Exit Function

Else
Reporter.ReportEvent micFail, vInfo, "Expected value = " & vExpectedVal & ". Actual value = " & vActualVal
Print "**FAIL***. " & vInfo & ". Expected value = " & vExpectedVal & ". Actual value = " & vActualVal


'Add FAIL event to TestLink variable
Environment.Value("EnvTLNotes") = Environment.Value("EnvTLNotes") & VBCrlf & "FAIL " & vInfo & ". Expected = " & vExpectedVal & ". Actual = " & vActualVal & ". Time: " & time


Exit Function

End If

End If

End Function
abrown2010
TestLink user
 
Posts: 1
Joined: Wed Jun 30, 2010 1:22 pm

Re: QTP and TestLink

Postby sunil8649 » Mon May 06, 2013 1:26 pm

This information looks helpful. I will give a try for my current project and post back the result as soon as possible.

Thanks
Sunil
sunil8649
TestLink user
 
Posts: 2
Joined: Thu May 02, 2013 5:24 pm


Return to General Testing and Test management



Who is online

Users browsing this forum: No registered users and 1 guest