| || |
object communication functions
I am starting to write code for a new QTP/UFT project from scratch.
I need to work with a lot of Push buttons, dropdowns, edit boxes and tables.
It seems simple, but I'm a little bit stuck on this idea:
I'd like to check the state of an object before using it, then use it, then check that it did the task OK.
For example...I have an edit box in a user defined variable:
Set myButton = Browser().Page().Object("bla bla") <--either from OR or Create.Description
My function with pseudo code looks like:
I have seen in Tarun's book that I could overwrite the functionality of the .Set() command but I don't want to "mess around" with the built in QTP/UFT functions.
Check that the edit box is editable
Send the current value to the result log as a comment
Enter the data
Report if the value was entered and stop the script if it did not work as expected
Is my idea above practical?
Can someone give me some sample code to show me how they have done this?
Kevin is there a reason for this as it seems like a BIG overhead to script creation. In the past the only specific checks I have done similar to this is when the test case says something like "verify the XYZ button is disabled"
Usually a test will implicitly verify whether the object you are trying to populate/click/select a value by failing if it is not accessible. As for the entered values, these are usually validated in DB/UI type checks in the later part of the script.
You could use a RegisterUserFunc method to override but you would have to do this for multiple object/methods which could become messy. It might also give your co-scripters a bit of a headache maintenance-wise in the future.
I'm not trying to sound negative but IMHO it lead to more more work rather than the intended.
I'm not sure why I started going in this direction. If QTP/UFT has a problem with the object it will send an error to the result log without having to write extra code.
If anyone else has additional opinions or thought on this, I'd appreciate your feedback.
kevin this depends on the design of framework .I Usually write a common function of all the methods for example Func(ObjectName,Method,Param1,Param2)
I did something like this exactly for an old VB project. Had a single data entry function for all types of objects. Switch statement inside there based on object type. Then would enter the data in the most reliable method I had found for that object type. Could also report out whether it had successfully entered the data correctly by reading it from the object immediately after entry, largely used that for debugging. Knowing that was the problem exactly where it occurred was much more useful than trying to figure it out from the test result(digging through forms to find offending data/calculations/printing/etc).
Haven't had to resort to that kind of thing with web apps. But for that old vb app with some 3rd party controls QTP was notorious for dropping characters and such at input. Had to actually enter strings with SendKeys one character at a time with a slight delay to more closely replicate human typing for it to work properly.
Last edited by NoUse4aName; 01-26-2014 at 10:35 AM.
Your function call is the idea that I have in my mind. Would you be able to show me how you create the object and also an example of one object. Maybe an edit box or button? Could you post the code here?
I would like to have a way to check that each object is reacting to what I asked it to do.
I will have a copy of QTP/UFT in a couple of days again. I want to find out how to make the object and then pass it into a function that does the operation like you and saikri are mentioning. I worked on a winRunner and two QTP projects. I did not make a copy of the code that I saw so I don't have the examples any more.
Am on on track? Can I put the object into a user defined variable and pass it to a function?
Set mObj = Browser().Page().Object()
mAvailable = mObj.GetROProperty("enabled")
If mAvailable Then
' Report not available
Last edited by bklabel1; 01-26-2014 at 01:32 PM.
Reason: Added the SET for an object
Yes Kevin, you can do that.
Yes Kevin, the above looks good - I will try to share you a piece of code i had earlier for the similar approach followed.
And this framework would go more like a Keyword Driven with all the actions written into functions.
yeah same which you did the same i did .here we have an extra check to our report for object existence . I wil give my piece of code once i reach my work