2010-06-20 6 views
2

J'essaie d'ajouter ConfirmDialogHandler au gestionnaire de dialogue et j'obtiens NullReferenceException. Cela se produit sur FF 3.6 avec la dernière version de Watin, le même code fonctionne sur IE7 et 8.Méthode Watin AddDialogHandler rejetant une exception de référence nulle dans FF

ConfirmDialogHandler confirmDialogHandler = new ConfirmDialogHandler(); 
    browser.AddDialogHandler(confirmDialogHandler); // --> exception here 

Toutes les idées?

Répondre

1

ancienne solution

trouvé le problème.

Le DialogWatcher n'a pas été initialisé lors de la session FF a été créé ajouté cette ligne à Watin code:

private void CreateFireFoxInstance(string url) 
    { 
     Logger.LogAction("Creating FireFox instance"); 

     UtilityClass.MoveMousePoinerToTopLeft(Settings.AutoMoveMousePointerToTopLeft); 

     var clientPort = GetClientPort(); 
     clientPort.Connect(url); 
     _ffBrowser = new FFBrowser(clientPort); 
     StartDialogWatcher(); // <-- Added line 
     WaitForComplete(); 
    } 

S'il vous plaît Remarque - Ceci est la solution de contournement

La solution proposée n'a pas travaillé Cette est ma solution de contournement: J'ai utilisé dll AutoIt et manipulé les popups par moi-même, exemple de code:

using AutoItX3Lib; 

    public static void RunAutomaticEnterCommand(Session session) 
    { 
     var autoIt = GetPopupHandle(); 
     autoIt.Send("{ENTER}"); 
     Thread.Sleep(1000); 
    } 


    /// <summary> 
    /// Cancel the popup 
    /// For FF 
    /// </summary> 
    /// <param name="session"></param> 
    public static void RunAutomaticCancelCommand(Session session) 
    { 
     var autoIt = GetPopupHandle(); 
     autoIt.Send("{TAB}"); 
     autoIt.Send("{ENTER}"); 
     Thread.Sleep(1000); 
    } 

    /// <summary> 
    /// Return the autoit popup handler 
    /// AutoIt is a script language, we using it to handle the firefox popups 
    /// </summary> 
    /// <returns></returns> 
    private static AutoItX3Class GetPopupHandle() 
    { 
     var autoIt = new AutoItX3Class(); 
     autoIt.AutoItSetOption("WinTitleMatchMode", 2); 
     const string partialTitle = "The page at"; //the popup in Firefox starts with this text 
     autoIt.WinWait(partialTitle, "", 30); 
     string fullTitle = autoIt.WinGetTitle(partialTitle); //Get the whole popup title 

     autoIt.WinActivate(fullTitle); //Get focis to the popup 
     if (autoIt.WinWaitActive(fullTitle, "", 20) == 0) 
     { 
      reporter.Report("Failed to get the FireFox popup handle", false); 
      return autoIt; 
     } 
     return autoIt; 
    } 
Questions connexes