Micro Focus QTP (UFT) Forums
QTP Test results will return exit codes - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: QTP Test results will return exit codes (/Thread-QTP-Test-results-will-return-exit-codes)

Pages: 1 2


QTP Test results will return exit codes - asrivastava - 06-16-2011

Hi,

I am new to QTP and working on a critical requirement.

I am using QTP11.0 and need qtp test results in the form of codes e.g. 1 = Pass, 0 = Fail etc. ..

How is that possible ?

Thanks in advance .

~ Ashish


RE: QTP Test results will return exit codes - rajpes - 07-05-2011

You can make use of filesystem for excel and write the values in columns testname and status as 0 or 1 depending on whether your script passed or failed in the next line of where you write those reporter.reportevent code


RE: QTP Test results will return exit codes - asrivastava - 07-06-2011

Thanks for reply ...

can you please elaborate the given solution as i am new to QTP... better if you provide some example...

Thanks in advance.




RE: QTP Test results will return exit codes - rajpes - 07-06-2011

Elaborate your requirement,where do you want to see the values 1 and 0? in the result file?


RE: QTP Test results will return exit codes - asrivastava - 07-07-2011

The requirement is : every test case should return exit/error codes e.g. 0 for pass, 1 for fail, 2 for stopped in the middle etc.

Test results displays in Run Results Viewer window in text i.e. Passed, Failed, Done and Warning but as per our requirement we need in numeric i.e. 0, 1, 3 and 3.

It would also fine if gets results in the form of codes in log/text file.

However i am also running tests from command prompt via vb script and after end of test a log file is generating with test status (Passed/Failed/Done/Warning) but we need in codes only.

Here is the code for getting the test status :
WScript.StdOut.Write "Test status: " + qtTest.LastRunResults.Status + vbCr

Hope you understand the issue ...

Thanks,
Ashish


RE: QTP Test results will return exit codes - rajpes - 07-07-2011

Possible Values of LastRunResults Are

Passed--The most recent run passed.
Failed--The most recent run failed.
Warning--The most recent run returned a warning.
Running--The test or component is currently running.
Stopped--The current run was stopped.
Paused--The current run is paused.
Not applicable--There are no run results for this test or component.

So why can't you use a select case with these values and write corresponding numeric values to the log.

Some dummy code here.

assuming you have an excel file with first column as "TestName", 2nd col as "status"

Code:
set fso=createobject("excel.application")
Set wb=fso.workbooks.open("D:\Documents and Settings\admin\Desktop\a.xls")
Set sh=wb.worksheets(1)

'i is iteration value in your loop
sh.cells(i,1)=environment("TestName")
retValue=qtTest.LastRunResults.Status

Select case retValue
case "Passed":sh.cells(i,2)=1
case "Failed":sh.cells(i,2)=0.
.
.
so on

End select

wb.save

wb.close
Set sh=nothing
Set wb=nothing
Set fso=nothing



RE: QTP Test results will return exit codes - asrivastava - 07-07-2011

I have implemented above code but I am getting "Type mismatch: 'environment'" error on code line :

Code:
sh.cells(i,1).Value = environment("TestName")

I have created one excel file and put TestName in first row and first column.


RE: QTP Test results will return exit codes - rajpes - 07-07-2011

i is the loop variable, if you have only one test replace i with 1
otherwise if you have many tests,use a loop with loop counter i


RE: QTP Test results will return exit codes - asrivastava - 07-07-2011

Now i am not using loop but still getting "Type mismatch: 'environment'" error. I am pasting the entire code. please check.

Code:
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = False ' Make the QuickTest application visible

qtApp.Open "D:\PrototypeTestCases\QTPProjects\Demo\App1", True 'Open the test in read-only mode

'set run settings for the test
Set qtTest = qtApp.Test
qtTest.Run

set fso=createobject("excel.application")
Set wb=fso.workbooks.open("D:\PrototypeTestCases\QTPProjects\Demo\App6\ResultCodes.xls")
Set sh=wb.worksheets(1)

'i is iteration value in your loop
sh.cells(1,1)=environment("TestName")
retValue=qtTest.LastRunResults.Status

Select case retValue
case "Passed":sh.cells(1,2)=1
case "Failed":sh.cells(2,2)=0.
'.
'.
'so on
End select

wb.save

wb.close
Set sh=nothing
Set wb=nothing
Set fso=nothing

WScript.StdOut.Write "Test status: " + qtTest.LastRunResults.Status + vbCr 'Check the results of the test run
qtTest.Close 'Close the test
qtApp.Quit 'Close the QTP'



RE: QTP Test results will return exit codes - rajpes - 07-07-2011

Code:
sh.cells(1,1)=qtTest .Environment("TestName")