问题
I'm using QTP 9.5 test my application written in Delphi. I got Delphi Add-in installed and QTP can identify Delphi controls. Most but not all, specially TLabel. QTP can not recognize this control and is being ignored by Object Spy. Any suggestion, tip, clues how to test labels ?
cheers !
回答1:
Have you tried with TStaticText instead of TLabel?
They are Labels with a Window Handle (descending from TWinControl instead of TGraphicControl) which means they can get Windows messages from the outside.
I'm guessing that it's your problem. (only a guess as I don't know QTP)
回答2:
It can detect controls like TSpeedButton? If not, this can be a sign that Qtp cannot detect controls that descend from TGraphicControl and therefore doesn't have a window handle.
回答3:
You may be able to write your own Delphi extender for QTP to handle this. There should be a pdf in your QTP install path: C:\Program Files\HP\QuickTest Professional\help\Extensibility\DelphiExtensibility.chm and DelphiExtensibility.pdf.
回答4:
If you still have to test it "as is" you probably have to go a more hard-coded way addressing the parent of those controls.
A window object in QTP through its methods allows finding a rectangular area containing the text, or clicking on a text found. If it's an area on the screen with the big amount of labels you can dump a whole screen to the text file and go with the text file comparison. You can also normalize text retrieved before doing comparison.
This approach is less robust but you can improve it if calculating rectangles dynamically, without hard-coding points wherever possible.
来源:https://stackoverflow.com/questions/1041383/how-to-test-labels-in-qtp