ohman
Member
Reged: 10/27/10
Posts: 41
|
|
I have been able to connect to SQL database using QTP and QTP is able to read results of query as well. However, one test case checks to see that query should not return any value at all. In this case, only column name of SQL table displays but no value is return at all. So, how do I tell QTP that if no value is returned then test case passes??
Dim con, rs
'OPEN DATABASE CONNECTION set con=createobject("ADODB.Connection") set rs=createobject("ADODB.Recordset") con.Provider = "sqloledb" con.Open("Server=SDRQA;Database=SDR;Trusted_Connection=yes") 'WRITE QUERY 'THIS QUERY RETURNS NO VALUE AT ALL rs.open "SELECT DISTINCT GroupProgramID FROM GroupProgramLinkage (NOLOCK) EXCEPT SELECT DISTINCT GroupProgramID FROM GroupProgram (NOLOCK)" , con
Dim a 'I AM STORING VALUE IN a Set a = rs.fields("0")
Problems: (1) When I write "print a", QTP fails. (2) When I write if a = " " QTP fails. (3) When I write if a = NULL QTP fails.
so how do I tell QTP that if query don't return any value at all, then its a PASS test case??
|
AnshooArora
Advanced Member
Reged: 10/27/07
Posts: 612
Loc: New Delhi, India
|
|
Its because you cannot directly print an "object". You need to print the output of its method.
try:
print a.name print a.value
-------------------- Regards,
Anshoo Arora
[AdvancedQTP] [LinkedIn] [Relevant Codes]
|
Tarun Lalwani
Veteran
Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
|
|
Few issue. Its not "0" it is 0
You should use
a = rs.fields(0)
Also do away with the Set operator, else you will get the field object
-------------------- Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **
KnowledgeInbox RSS
|
ohman
Member
Reged: 10/27/10
Posts: 41
|
|
I am attaching screenshot of SQL query here. When I run above mention code, I receive following error message from QTP...
Code: Dim con, rs
'OPEN DATABASE CONNECTION set con=createobject("ADODB.Connection") set rs=createobject("ADODB.Recordset") con.Provider = "sqloledb" con.Open("Server=SDRQA;Database=SDR;Trusted_Connection=yes") 'WRITE QUERY 'THIS QUERY RETURNS NO VALUE AT ALL rs.open "SELECT DISTINCT GroupProgramID FROM GroupProgramLinkage (NOLOCK) EXCEPT SELECT DISTINCT GroupProgramID FROM GroupProgram (NOLOCK)" , con
Set a = rs.fields(0) print a.Value
at print a.Value line, I am getting this error message from QTP:
Run Error: Either BOF or EOF is True, or the record has been deleted. Requested operation requires a current record.
Basically, QTP throws error message since there isn't any record. But, what do I write to check whethere no record is returns at all??
|
Rajkumar_Rajangam
Veteran
Reged: 10/22/10
Posts: 3136
Loc: Norway
|
|
If Not rs.EOF Then Set a = rs.fields(0) print a.Value Else 'Report no records found End If
-------------------- Rajkumar
|
ohman
Member
Reged: 10/27/10
Posts: 41
|
|
Thank you Mr.Raj. Appreicate it!!
|
AnemUday
Member
Reged: 01/18/08
Posts: 226
|
|
If you are sure that the query returns a single value, no need of verifying the EOF.
And just add to the Raj's reply, u can directly get the value like below: print rs.fields(0).value
0r
print rs.fields("give your columnname").value
Or
print rs.fields.Item("give your columnname").value
-------------------- For more tips and resources visit my below blogs:
http://qtpftvideos.blogspot.in/
http://hpsqtp.blogspot.com/
Edited by AnemUday (03/13/12 12:12 PM)
|