Overload SaveAsDialog and GenericDialog handlers

6 posts, 0 answers
  1. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 20 Jun Link to this post

    The code that is below is something that I quite frequently have to use in order to export data from my application and handle the overwrite box if it pops up. My issue is, I have to copy and paste this in every single new test that I do and make sure I change all the right values. What I would like to do is put this in a 'library' file so I can just access a single function call in each test that will handle all of this, instead of copying and changing ALL of this text every single time. This is in an attempt to make my project a little smaller, and make it easier to maintain and create.

     

    However. The manager class, and call to the element to open the dialog handler are getting in my way to moving this into a separate class file. Does anybody know of a way I might be able to accomplish this?

     

    GenericDialog genDialog = new GenericDialog(Manager.ActiveApplication, "Save As", false, 6);
    SaveAsDialog saveDlg = SaveAsDialog.CreateSaveAsDialog(Manager.ActiveApplication, DialogButton.SAVE, queryFilePath);
    Manager.DialogMonitor.AddDialog(saveDlg);
    Manager.DialogMonitor.AddDialog(genDialog);
    Manager.DialogMonitor.Start();
                
    // Wait for '1000' msec.
    // Handle the overwrite box on save.
    Applications.dTIMSexe.dTIMS_V9_For_Windows.ExportAllTextblock.User.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 23, 19, ArtOfTest.Common.OffsetReference.TopLeftCorner, ArtOfTest.Common.ActionPointUnitType.Percentage, ((System.Windows.Forms.Keys)(0)));
                        
    saveDlg.WaitUntilHandled(60000);
    Manager.DialogMonitor.Stop();
    Manager.DialogMonitor.RemoveDialogs(saveDlg, genDialog);

  2. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    81 posts

    Posted 21 Jun Link to this post

    Hello Aaron,

    There is a way to use external to your tests resource file. In this article you may find all necessary information and "how to".

    When you create the file that will contain your common logic - refer in it all necessary dlls. Here is sample class with a method that handle a "Save as" dialog:

    using ArtOfTest.WebAii.Core;
    using ArtOfTest.WebAii.Controls.HtmlControls;
    using ArtOfTest.WebAii.Win32.Dialogs;

    public
    class Resource
    {
        public static void HandleDialog(HtmlControl element)
        {
             DownloadDialogsHandler dialog = new DownloadDialogsHandler (Manager.Current.ActiveBrowser, DialogButton.SAVE, @"C:\myfile.txt", Manager.Current.Desktop);
             Manager.Current.DialogMonitor.Start();
             element.Click();
             dialog.WaitUntilHandled(20000);
        }
    }

    In the coded step you may call this method as:
    Resource.HandleDialog(Pages.DialogsTestingPage.x1KBStrongTag);

    Let me know if that answers your question.

    Regards,
    Nikolay Petrov
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 21 Jun in reply to Nikolay Petrov Link to this post

    Mostly. However trying to call Manager in an outside class, I get the attached error. And I'm honestly not sure how to instantiate a Manager object as I have no clue what I would pass it.
  4. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 21 Jun in reply to Aaron Link to this post

    Finally figured out a work around. If anything in this should be accomplished differently, please correct me.

     

    public static void HandleSaveDialog(ArtOfTest.WebAii.Controls.Xaml.Wpf.TextBlock element, string filePath)
    {
        // Create an instance of the Manager class to allow access to its functions.
        Settings mySettings = new Settings();
        Manager myManager = new Manager(mySettings);

        // Connect the manager to the first running instance of dTIMS.
        myManager.ConnectToApplication(System.Diagnostics.Process.GetCurrentProcess());

        // Create the dialog handlers.
        GenericDialog genDialog = new GenericDialog(myManager.ActiveApplication, "Save As", false, 6);
        SaveAsDialog saveDlg = SaveAsDialog.CreateSaveAsDialog(myManager.ActiveApplication, DialogButton.SAVE, filePath);

        // Add the save dialog handler to the monitor, and start the monitor.
        myManager.DialogMonitor.AddDialog(saveDlg);
        myManager.DialogMonitor.Start();

        // Click on the element passed in that will create the dialog.
        element.User.Click();

        // Wait until the dialog is handled, and then stop the monitor.
        saveDlg.WaitUntilHandled(30000);
        myManager.DialogMonitor.Stop();
                
        // Add the generic dialog handler to the monitor, and start the monitor.
        myManager.DialogMonitor.AddDialog(genDialog);
        myManager.DialogMonitor.Start();

        // Sleep for 3 seconds to give an overwite dialog to occur.
        System.Threading.Thread.Sleep(3000);

        // Stop the monitor, and remove both dialog from it.
        myManager.DialogMonitor.Stop();
        myManager.DialogMonitor.RemoveDialogs(saveDlg, genDialog);
    }

  5. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    81 posts

    Posted 24 Jun Link to this post

    Hi Aaron,

    There is one thing to have in mind in this case. It is not a good practice to make more than one instance of the Manager object. In this case is better to use in this method the initial object which can be invoke as:
    Manager.Current
    Have a look at the example I proposed earlier.

    Regards,
    Nikolay Petrov
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  6. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 24 Jun in reply to Nikolay Petrov Link to this post

    Oh, thanks! I honestly didn't even notice the '.Current' in your earlier post.
Back to Top