2011-04-12 193 views
1

我想使用Win32 :: GuiTest來測試基於InstallShield的卸載過程。我可以打開控制面板,找到應用程序,然後調用InstallShield,但是我沒有做任何事情似乎讓我選擇安裝程序中的「刪除」按鈕。到目前爲止,我得到了:爲什麼我可以使用Win32 :: GuiTest在XP上驅動InstallShield而不是在Windows 7上?

sub uninstall($;$) { 
    my ($name, $force) = @_; 
    if (! defined($force)) { 
     $force=0; 
    } 

    my @windows; 
    # Control Panel window 
    my $cpwin; 
    my $w; 
    my $text; 
    # Install Shield window 
    my $iswin; 

    # Run the Control Panel (In windir, do `control appwiz.cpl`) 
    system("cd %windir% && control appwiz.cpl"); 
    sleep 1; 
    print("Opened control panel\n"); 

    # Get the Window ID of the control panel 
    # FIXME - this label is system specifie (W7) 
    @windows = FindWindowLike(undef, "Programs and Features", ""); 
    $cpwin = $windows[0]; 
    printf("Found CP window ID %x\n", $cpwin); 

    # Get the Folder View window of the control panel 
    # Find the list of applications 
    @windows = FindWindowLike($cpwin, "FolderView"); 
    $w = $windows[0]; 

    # Find program in the list 
    if (Win32::GuiTest::SelListViewItemText($w, $name) == 0) { 
     printf("Could not find '$name'.\n"); 
     return -1; 
    } 

    # Invoke the installer for by pressing [Return] 
    Win32::GuiTest::SendKeys("~"); 
    # Wait for the "initializing the wizard" window 
    @windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 5); 
    # Wait for the real installer window 
    sleep 10; 
    @windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 3); 
    $iswin = $windows[0]; 
# Win32::GuiTest::WaitWindow("Remove"); 
    printf("Found IS window ID %x\n", $iswin); 
# Win32::GuiTest::SetFocus($iswin); 

    @windows = FindWindowLike($iswin, "&Remove", "Button"); 
    my $remove = $windows[0]; 
    printf("Found remove button %x\n", $remove); 
    Win32::GuiTest::PushButton($remove); 
# Win32::GuiTest::SetFocus($remove); 
# Win32::GuiTest::SendKeys("%r"); 
# Win32::GuiTest::MouseClick("Remove",$iswin); 
# Win32::GuiTest::CheckButton($remove); 
# Win32::GuiTest::SendKeys("{DOWN}{DOWN}"); 

# Win32::GuiTest::MouseClick("Next",$iswin); 
# Win32::GuiTest::PushChildButton($iswin, "Cancel"); 

我試過的東西(註釋掉,最後)都沒有任何效果。

我在Windows 7上使用ActivePerl和Win32 :: GuiTest,如果有任何問題。

(成爲的那種。我的Perl可能很爛。我有> 25年的經驗編程,但比在Perl一個月的時間。)

+0

我轉移到試圖駕駛的NSIS安裝。我也無法讓它工作。我的同事把它用在了他真正的XP系統上,但我的W7虛擬機中有一個非啓動器。 OTOH,記事本示例(http://search.cpan.org/dist/Win32-GuiTest/lib/Win32/GuiTest/Examples.pm#eg/notepad.pl)對我來說工作得很好。 – 2011-04-12 18:02:14

回答

0

,我試圖以驅動安裝的事實,似乎是一個紅色的鯡魚。在XP(即使在虛擬機),這工作正常。我懷疑問題在於安裝程序顯示對話框,而記事本提供了一個窗口,這些窗口在W7中的處理方式與XP不同。我會回到爲什麼W7無法正常工作,但是XP現在是我必須要做的,所以這已經足夠了。

0

Win32::GuiTest::PushButton方法將按鈕Text或ID作爲參數,而不是窗口/控件對象。所以你根本不需要調用FindwindowLike方法。

但是Win32::GuiTest::PushButton只從前景窗口查找按鈕,這可能不適合所有情況。應該使用Win32::GuiTest::PushChildButton

請試試這個方法:

#@windows = FindWindowLike($iswin, "&Remove", "Button"); 
#my $remove = $windows[0]; 
#printf("Found remove button %x\n", $remove); 
sleep 10; 
Win32::GuiTest::PushChildButton($iswin, "&Remove", 50); 
+0

感謝您的建議,但這也不起作用。 – 2011-04-14 11:50:09

+0

按下按鈕之前的「睡眠10」怎麼樣? – 2011-04-18 02:58:04

相關問題