This is a migrated thread and some comments may be shown as answers.

Overload SaveAsDialog and GenericDialog handlers

5 Answers 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 20 Jun 2016, 08:22 PM

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);

5 Answers, 1 is accepted

Sort by
0
Nikolay Petrov
Telerik team
answered on 21 Jun 2016, 02:55 PM
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
 
0
Aaron
Top achievements
Rank 1
answered on 21 Jun 2016, 06:07 PM
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.
0
Aaron
Top achievements
Rank 1
answered on 21 Jun 2016, 07:36 PM

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);
}

0
Nikolay Petrov
Telerik team
answered on 24 Jun 2016, 12:41 PM
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
 
0
Aaron
Top achievements
Rank 1
answered on 24 Jun 2016, 12:51 PM
Oh, thanks! I honestly didn't even notice the '.Current' in your earlier post.
Tags
General Discussions
Asked by
Aaron
Top achievements
Rank 1
Answers by
Nikolay Petrov
Telerik team
Aaron
Top achievements
Rank 1
Share this question
or