开发者

Making a object class name a parameter

I have a TC script that handles report options for a variety of screens. The window class name changes on each screen and, as I want this script to work in a translated environment, the window caption will be changing as well. The first part works correctly 开发者_JAVA技巧but how to I account for the changing window name as well? If I remove the caption, TC bombs with an ambiguous window recognition error.

Current code snippet (with the caption of one screen) :

w := p.WaitWindow('*', 'Options', 1, 10000);   
if w.Name='frmBasicOpt' then
begin
....

Can I set the class name as a parameter that is fed in so I can leave out the caption? If so, how can I do this?

Head... hurt.

Thanks!


Not sure I understand the task, but I will try to help to the extent of my understanding. So, the window class name is a dynamic thing, that's why you masked it with a wildcard. But you tell that you want to use the class name anyway if you are able to parameterize it. So, it seems like there is a way to get the class name during test execution from somewhere. If so, you can put the class name to a variable, and pass this variable to the WaitWindow method as a parameter, and mask the caption to avoid using language-specific captions:

clsName := ....; // get it from somewhere
w := p.WaitWindow(clsName, '*', 1, 10000);
if w.Name='frmBasicOpt' then
begin

If my understanding is not correct and there is no way to know the class name beforehand, you may consider using a different approach to identify the Options window without specifying the caption. The possible solution include:

  1. When the dialog opens, it becomes active. So, you can get the dialog through Sys.Desktop.ActiveWindow.

  2. If this is an MFC application, pay attention to the ControlID property of the window - it's something that can be set in the application's code, to be used for object recognition. So, you can use the FindChild method to find the window by the property value.

  3. If the window has some child objects that are specific only to this window, you can create a function that will get all child windows of the Process object (FindAllChildren), iterate through the list and check which of them has those specific child objects.

Does anything for this work for you? If not, then a little bit more information about your task could probably help me make other suggestions.

Alex

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜