未来已来

hp - WinRunner 百问 一

上一篇 / 下一篇  2008-09-21 14:03:34 / 个人分类:自动化测试

How to Close all Browsers that were opened before WinRunner?

1.The close_browsers function will close browsers that were opened
before WinRunner
function close_browsers()
{
   auto count, count2;
   count = 0;
   while (win_exists("{class: window,MSW_class:browser_main_window,location:" & count & "}")==0)
      count++;
   for (count2 = 0; count2 < count; count2++)
      win_close("{class: window,MSW_class:browser_main_window,location:"0"}"); 
   # close IE-spawned browser windows
   count = 0;
   while (win_exists("{class: window,MSW_class: IEFrame,location:" &
count & "}")==0)
      count++;
   for (count2 = 0; count2 < count; count2++)
      win_close("{class: window,MSW_class: IEFrame,location:"0"}");

   # close browsers open beforeWinRunner

   set_class_map("mic_unknown_class", "window");
   set_record_attr("mic_unknown_class", "class", "MSW_class",
"location");
   set_record_method("mic_unknown_class", RM_RECORD); 
   count = 0;
   while (win_exists("{class: window,MSW_class:
mic_unknown_class,location: " & count & "}")==0)
      count++;
   for (count2 = 0; count2 < count; count2++)
      win_close("{class: window,MSW_class: mic_unknown_class,location:" & count & "}");
}

2. This version of the function may execute a little faster when using
Netscape:

public function close_all_browsers()
{
    auto desc = "{class: window,MSW_class:
browser_main_window,NSTitle: \"Browser Main
Window\",location:",x,y,done;
    auto desc2 = "{class: window,label: \"!.*Microsoft Internet
Explorer\",MSW_class: IEFrame,location:";
    auto val = 50; # this line acutally sets the number of browser
windows to close
    x = val;
    done=0;
    while(x >= 0)
    {
        y = desc&x--&"}";
        if(E_OK == win_exists(y))
        {
            win_activate(y);
            win_close(y);
        }
    }
    x = val;
    while(x>=0)
    {
        y = desc2&x--&"}";
        if(E_OK == win_exists(y))
        {
           win_activate(y);
            win_close(y);
        }
    }
    return E_OK;
}

3. You can use the undocumented _web_browser_close function to close
all browsers that were opened afterWinRunner. Using empty quotes ""
will close all browsers opened afterWinRunner. To close a specific
browser, pass the logical name of the browser to the function.

_web_browser_close("");

EXAMPLE:
# Close all open browser windows:
_web_browser_close("");

Here is a function which uses _web_browser_close to close the browsers
opened afterWinRunnerand will also close the browsers opened before
WinRunner.

public function close_all_browsers2()
{

    # close browser opened afterWinRunner
    _web_browser_close("");

    # close browsers open beforeWinRunner
    set_class_map("mic_unknown_class", "window");
    set_record_attr("mic_unknown_class", "class", "MSW_class",
"location");
    set_record_method("mic_unknown_class", RM_RECORD);

    while (win_exists("{class: window, MSW_class: mic_unknown_class,
location: 0}") == E_OK)
    {
       win_activate("{class: window, MSW_class: mic_unknown_class,
location: 0}");
       win_close("{class: window, MSW_class: mic_unknown_class,
location: 0}");
    }

}

4. If the functions above have problems closing browsers opened before
WinRunner, you can try using the following code in one of the
functions. This code checks the items in the Shell Tray (the toolbar
at the bottom that lists the running applications) and selects the
ones that correspond with the browsers. This should bring the browser
to the foreground, at which point the type function can be used to
press Alt-F4 in order to close the window. This should work on Windows
95, 98, NT 4.0, and 2000. This will not work on Windows XP in its
current form, due to the way that Windows XP represents the items in
the Shell Tray as a toolbar, rather than a tab control. Similar
functionality should work, however, for Windows XP using toolbar
functions, instead of tab functions.

set_window("Shell_TrayWnd", 3);
tab_get_info("tab", "count", count);
for(i = count-1; i > 0; --i)
{
    tab_get_item("tab", i, item);
    if(match(item, ".*Microsoft Internet Explorer") > 0 || match(item,
".*Netscape") > 0)
    {
       tab_select_item("tab", "#" & i);
       wait(1);
       type("<kAlt_L-kF4>");
       wait(1);
    }

}


TAG: 自动化测试

 

评分:0

我来说两句

Open Toolbar