Micro Focus QTP (UFT) Forums
I couldn't rectify the error in following script..pls helpme frds.. - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: I couldn't rectify the error in following script..pls helpme frds.. (/Thread-I-couldn-t-rectify-the-error-in-following-script-pls-helpme-frds)



I couldn't rectify the error in following script..pls helpme frds.. - Kishore_J - 01-23-2011

Hi Frds,

Please help me on this following script..I have written Function script to enter username,pwd fields and verify status.
'**** Following script for ActiTIME-Login" screen.

Code:
Set un = Browser("ActiTIME-Login").Page("ActiTIME-Login").webedit("username")
Set pwd =Browser("ActiTIME-Login").Page("ActiTIME-Login").webedit("pwd")
Set btn = Browser("ActiTIME-Login").Page("ActiTIME-Login").webbutton("Login now")

Call objectset (un, "admin")
Call objectset (pwd, "manager")
Call objectset(btn)

Function objectset(testobj, sinput)
   sobjname = testobj.Tostring
   Status = verifyobjexistandenabled(testobj)
   If status = True Then
       Desc = "setting" &sinput& "in to"&sobjname
       Reporter.ReportEvent micPass, "objectset", Desc
       testobj.setsinput
      
     Else
     Exittest
      
   End If
End Function
*****************************
When i am executing the above script it's giving error message
"Type Mismatch: Status = verifyobjexistandenabled(testobj)"

Please help me what is the problem in the above script??
What is the object method we can use for verify status (For web & Windows)

Thanks in Advance,


RE: I couldn't rectify the error in following script..pls helpme frds.. - cdesserich - 01-24-2011

Usually when you get that error, the function is not associated with the test, or the function name is misspelled. Where do you have the function "verifyobjexistandenabled()" defined? If it is in an external function library file, make sure it is associated with your test. Also make sure the definition is spelled the same way.


RE: I couldn't rectify the error in following script..pls helpme frds.. - Kishore_J - 01-24-2011

Thanks for your replay


RE: I couldn't rectify the error in following script..pls helpme frds.. - cdesserich - 01-24-2011

Did you figure it out?


RE: I couldn't rectify the error in following script..pls helpme frds.. - Kishore_J - 01-25-2011

No. Actually, here i used Function as --Function objectset(testobj, sinput)- and in the same script only i am calling. But, i couldn't recognise what i did mistake for status verification.."Status = verifyobjexistandenabled(testobj)"

Can you please elabrate this..and also if you give some info about what are the methods will support for window applications..

Thanks in advance,


RE: I couldn't rectify the error in following script..pls helpme frds.. - cdesserich - 01-26-2011

I'm not sure what you are trying to accomplish here. You seem to be avoiding QTP native functions. I would code this something more like this:

Code:
With Browser("ActiTIME-Login").Page("ActiTIME-Login")

    If .WebEdit("username").Exist() Then
        If .WebEdit("username").GetROProperty("disabled") <> 1 And _
        .WebEdit("username").GetROProperty("readonly") <> 1 Then

            .WebEdit("username").Set "admin"
            
        End If
    End If


    If .WebEdit("pwd").Exist() Then
        If .WebEdit("pwd").GetROProperty("disabled") <> 1 And _
        .WebEdit("pwd").GetROProperty("readonly") <> 1 Then

            .WebEdit("pwd").Set "manager"
            
        End If
    End If
    
    .WebButton("Login now").Click
    
End With

If you are trying to create a reusable function for checking if the object exists and is enabled, you could create a separated function library and do something like the code below putting the ExistAndEnabled function in the separate library and associating it to your test. If it is defined in the test, the RegisterUserFunc statement must be executed before the function can be used:

Code:
Function ExistsAndEnabled(test_object)
    ExistsAndEnabled = False
    
    If test_object.Exist(0) Then
        If test_object.GetROProperty("disabled") <> 1 And test_object.GetROProperty("readonly") <> 1 Then
            ExistsAndEnabled = True
        End If
    End If
End Function
RegisterUserFunc "WebEdit", "ExistsAndEnabled", "ExistsAndEnabled"


If Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("username").ExistsAndEnabled() Then
    Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("username").Set "admin"
End If

If Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("pwd").ExistsAndEnabled() Then
    Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("pwd").Set "manager"
End If

Browser("ActiTIME-Login").Page("ActiTIME-Login").WebButton("Login now").Click

I'm not sure if this is going to help you or not, but I hope it does.


RE: I couldn't rectify the error in following script..pls helpme frds.. - Kishore_J - 01-26-2011

Thanks for your helping me in this..yea, i got it...thank you very much..


RE: I couldn't rectify the error in following script..pls helpme frds.. - cdesserich - 01-26-2011

No problem. Hope I helped.