Beispiel #1
0
 public static GuiDialog GetDialog(ApplicationLauncher program, AutomationElement parentWindow, string caption)
 {
     //kan kanskje få til noge med: window.GetMessageBox() i hoved dsl-klassen
     if (_cachedDialog == null || _cachedDialog.Caption != caption) {
         var dialog = program.GetDialog(caption);
         _cachedDialog = new GuiDialog(dialog, caption);
         _currentProgram = program;
         _currentParentWindow = parentWindow;
     }
     return _cachedDialog;
 }
Beispiel #2
0
 public override void GetThisWindow()
 {
     _cachedDialog = GetDialog(_currentProgram, _currentParentWindow, Caption);
 }
Beispiel #3
0
 public static void InvalidateCache()
 {
     _cachedDialog = null;
 }
 public void Close()
 {
     try {
         if (Process != null && !Process.HasExited) {
             List<AutomationElement> dialogs = null;
             try {
                 var mainWindow = GetMainWindow();
                 dialogs = mainWindow.FindAllChildrenByByLocalizedControlType("Dialog").ToList();
             } catch (AutomationElementNotFoundException) {
                 //I expect not to find these dialogs.
             }
             if (dialogs != null) {
                 foreach (var d in dialogs) {
                     Thread.Sleep(1000);
                     WaitForInputIdle();
                     var errorDialogHeading = d.Current.Name;
                     string screenShotFilename = string.Empty;
                     try {
                         screenShotFilename = ScreenShooter.SaveToFile();
                     } catch (Exception ex) {
                         Log.Error("Exception while trying to save screenshot: " + ex.Message, ex);
                     }
                     Log.Error(string.Format("Error dialog labeled \"{0}\" found when trying to close program. Screenshot: {1}", errorDialogHeading, screenShotFilename));
                     try {
                         var guiDialog = new GuiDialog(d, errorDialogHeading);
                         guiDialog.CloseDialog();
                     } catch (Exception ex) {
                         Log.Error(string.Format("Attempted to close dialog labeled \"{0}\", but an exception occurred.", errorDialogHeading), ex);
                     }
                 }
                 if (!ConnectedInsteadOfStarted)
                     KillProcess();
                 Assert.AreEqual(0, dialogs.Count, "Error dialogs found when trying to close program.");
             }
         }
     } finally {
         if (!ConnectedInsteadOfStarted) {
             KillProcess();
         }
         if (RunApplicationClearUp && ApplicationClearAfterTestRun != null)
             ApplicationClearAfterTestRun();
         foreach (var file in FilesToDelete) {
             if (File.Exists(file)) {
                 try {
                     File.Delete(file);
                 } catch (Exception ex) {
                     Log.Error(string.Format("Failed to delete file during cleanup. Filename: {0}", file), ex);
                 }
             }
         }
         foreach (var directory in DirectoriesToDelete) {
             if (Directory.Exists(directory)) {
                 try {
                     Directory.Delete(directory, true);
                 } catch (Exception ex) {
                     Log.Error(string.Format("Failed to delete directory during cleanup. Directory: {0}", directory), ex);
                 }
             }
         }
     }
 }