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

Confirm dialog not handled in batch execution

10 Answers 182 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rohit
Top achievements
Rank 1
Rohit asked on 14 Dec 2011, 10:49 AM
Hi,
I am using MBunit tests for UI automation. My test involves clicking on OK button on a confirm dialog. The test work fine when executed individually. But if i run multiple tests in a class where few other tests are executed before the test involving confirm dialog, the dialog is not handled:

I have tried following option:

1. confirmDialog = new ConfirmDialog(ActiveBrowser, DialogButton.OK);  

      Manager.DialogMonitor.AddDialog(confirmDialog);

2. Manager.DialogMonitor.AddDialog(AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK));
    Manager.DialogMonitor.Start();

3. Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);


But none is working in batch, however they all are working fine if test is executed alone. Please guide if there is any other was to handle dialogs.

Thanks,
Rohit

10 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 19 Dec 2011, 07:23 PM
Hi Rohit,

It sounds like you did not remove the first dialog from the Monitor:

Manager.LaunchNewBrowser();
 
ConfirmDialog cd = ConfirmDialog.CreateConfirmDialog(ActiveBrowser, DialogButton.OK);
Manager.DialogMonitor.AddDialog(cd);
Manager.DialogMonitor.Start();
 
ArtOfTest.WebAii.Core.Browser frSub = ActiveBrowser.Frames["view"];
HtmlInputButton show = frSub.Find.ByExpression<HtmlInputButton>("value=Show a confirm box");
show.Click();
 
Manager.DialogMonitor.RemoveDialog(cd);

If you continue to have difficulty, please provide the full code for two tests that demonstrate the behavior.

Regards,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rohit
Top achievements
Rank 1
answered on 20 Dec 2011, 06:42 AM
Hi Anthony,

There is only one dialog involved in all tests. Please find the code below. The problem is that the code works fine when this is the first test to be executed. If followed by any other tests, it fails. Please let me know if there is a way to click on OK button through keyboard events.

    [TestFixture]
    class e_Cancel : BaseTest
    {

        [SetUp]
        public void MyTestInitialize()
        {
            Initialize(false);
        }

        [TearDown]
        public void MyTestCleanUp()
        {
           
        }

        [FixtureTearDown]
        public void FixtureCleanup()
        {
           

            ShutDown();
            this.CleanUp();
        }
        private Pages _pages;

        public Pages Pages
        {
            get
            {
                if (_pages == null)
                {
                    _pages = new Pages(Manager.Current);
                }
                return _pages;
            }
        }
           
     Manager.LaunchNewBrowser();
            Pages Pages = new Pages(Manager);

            // Navigate to : 'http://wid046:555/sites/t1'
            ActiveBrowser.NavigateTo("http://wid046:555/sites/t1");

            ConfirmDialog cd = ConfirmDialog.CreateConfirmDialog(ActiveBrowser, DialogButton.OK);
            Manager.DialogMonitor.AddDialog(cd);
            Manager.DialogMonitor.Start();

            // Click 'WINSHUTTLESpan'
            Pages.HomeS10.WINSHUTTLESpan.Click(false);

            // Click 'PlaceHolderMainHlnManageScheduledJobsLink'
            Pages.WINSHUTTLECENTRAL3.PlaceHolderMainHlnManageScheduledJobsLink.Click(false);

            HtmlAnchor file = Pages.ManageScheduledJobs0.Find.ByContent<HtmlAnchor>("http://wid046:555/sites/t1/DataFiles/testfileAPCancel1.xlsx");
            HtmlTableRow row = file.Parent<HtmlTableRow>();

            HtmlInputCheckBox chkbox = row.Find.ByAttributes<HtmlInputCheckBox>("id=~_chkDelete", "type=checkbox");
            chkbox.Check(true, true);

            Pages.ManageScheduledJobs0.PlaceHolderMainBtnDeleteSubmit.Click(false);
            System.Threading.Thread.Sleep(5000);
            Manager.DialogMonitor.RemoveDialog(cd);
            Pages.ManageScheduledJobs0.PlaceHolderMainLblMessageSpan.AssertContent().TextContent(ArtOfTest.Common.StringCompareType.Contains, "Jobs deleted successfully.");                      


Thanks,
Rohit
0
Anthony
Telerik team
answered on 21 Dec 2011, 09:39 PM
Hello Rohit,

The code looks good. How does the test fail? What specific error or exception do you get? What line of code does it point to?

The line of code you mentioned in point three of your original post is the correct way to invoke the Enter key, however we don't recommend using that to handle dialogs. 

You might try inserting an additional line of code at the beginning of the test. It's possible the UnexpectedDialogAction setting is interfering. You can set that to DoNotHandle to explicitly handle all dialogs yourself:

Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;

Kind regards,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rohit
Top achievements
Rank 1
answered on 22 Dec 2011, 07:32 AM
Hi,

The dialog opens and gets closed automatically. No exception or error is generated, the script fails when it couldnt find the element mentioned in next step.

Even keypress is not working. I have also tried with
Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;

But still the same issue, works alone, not in batch even when all setup and teardown functions are called again.

Thanks,
Rohit
0
Anthony
Telerik team
answered on 22 Dec 2011, 11:27 PM
Hello Rohit,

I saw similar behavior in my testing with dialog handling in an MbUnit test, although it is slightly different from what you're experiencing.

  • When running two MbUnit tests (one of which handles dialogs) in Visual Studio, it worked as expected.
  • When loading the MbUnit dialog test and running it with the Gallio Icarus test runner, the dialog was not handled. I believe this to be a bug and filed a report for it. You can track the PITS Issue here: Public URL

Unfortunately I don't have a work-around to offer you in the meantime.

Greetings,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Duncan
Top achievements
Rank 1
answered on 22 May 2014, 02:34 PM
 private static GenericDialog dlg;
        private static ConfirmDialog confirmdialog;
        private static SaveAsDialog savedialog;

        [BeforeFeature()]
        public static void Setup()
        {
            _testManager = new Manager(new Settings());
            _isLoggedIn = false;
            Settings.Current.Web.EnableSilverlight = true;
            Settings.Current.Web.RecycleBrowser = true;
            Settings.Current.Web.DefaultBrowser = BrowserType.InternetExplorer;
            Settings.Current.ClientReadyTimeout = 50000;
            Settings.Current.ExecuteCommandTimeout = 60000;
            Settings.Current.ExecutionDelay = 100;
            Settings.Current.WaitCheckInterval = 500;
            Settings.Current.SimulatedMouseMoveSpeed = 0.5f;
            Settings.Current.Web.EnableUILessRequestViewing = false;
            Settings.Current.QueryEventLogErrorsOnExit = false;
            Settings.Current.Web.EnableScriptLogging = false;
            Settings.Current.AnnotateExecution = true;
            Settings.Current.AnnotationMode = AnnotationMode.All;
            Settings.Current.Web.LocalWebServer = LocalWebServerType.None;
            _testManager.Start();
            _testManager.LaunchNewBrowser();
            _testManager.ActiveBrowser.NavigateTo(url);
            _testManager.ActiveBrowser.Window.Maximize();
            _app = _testManager.ActiveBrowser.SilverlightApps()[0];

            _app.RefreshVisualTrees();
            dlg = new ArtOfTest.WebAii.Win32.Dialogs.GenericDialog(_testManager.ActiveBrowser, "", true);
            savedialog = SaveAsDialog.CreateSaveAsDialog(_testManager.ActiveBrowser, DialogButton.SAVE, _reportPathAndFileName, _testManager.Desktop);
            confirmdialog = ConfirmDialog.CreateConfirmDialog(_testManager.ActiveBrowser, DialogButton.YES);   
    
            dlg.HandlerDelegate = new ArtOfTest.WebAii.Win32.Dialogs.DialogHandlerDelegate(d =>
            {
                ArtOfTest.Common.Win32.Window okButton = ArtOfTest.Common.Win32.WindowManager.FindWindowRecursively(d.Window.Handle, "OK", false, 0);
                ArtOfTest.Common.Win32.Window saveButton = ArtOfTest.Common.Win32.WindowManager.FindWindowRecursively(d.Window.Handle, "Save As", false, 0);
                ArtOfTest.Common.Win32.Window confirmButton = ArtOfTest.Common.Win32.WindowManager.FindWindowRecursively(d.Window.Handle, "Yes", true, 1000);
                
                _lastDialogTitle = d.Window.Caption;
                
                var dd = d.Window.Handle;
                if (okButton != null)
                    _testManager.Desktop.Mouse.Click(MouseClickType.LeftClick, okButton.Rectangle);
                else if (saveButton != null)
                    _testManager.Desktop.Mouse.Click(MouseClickType.LeftClick, saveButton.Rectangle);
                else if (confirmButton != null)
                {
                    _testManager.Desktop.Mouse.Click(MouseClickType.LeftClick, confirmButton.Rectangle);
                    confirmdialog.HandleCount = 1000;
                }

            });

            _testManager.DialogMonitor.AddDialog(savedialog);
            _testManager.DialogMonitor.AddDialog(dlg);            
            _testManager.DialogMonitor.AddDialog(confirmdialog);
            _testManager.DialogMonitor.Start();
        }

The bit that really got me was getting the Confirm button handle event to trigger. This was done by incrementing the Handle Count.

The bit of code calling this stuff was

            // save the report to a loc
            _app.FindName<RadButton>("btnSaveReport").User.Click();

            //Wait until handled
            savedialog.WaitUntilHandled();
            confirmdialog.WaitUntilHandled();  (THIS NEVER FINISHED)  until I fix with handle count
            
0
Boyan Boev
Telerik team
answered on 27 May 2014, 05:58 AM
Hello Duncan,

Thank you for sharing your knowledge and code.

We appreciate it.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
dan
Top achievements
Rank 1
answered on 31 Oct 2016, 09:41 PM

Hi Anthony,

I know this is an old thread, but I am having the same issue.

I tried adding

Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;

 

to me code, but it did not help.

The step builder's 'Handle Confirm Dialog' does handle the dialog, but I need to have it myself, as it may not always occur.

 

I've tried..

 

public void initAlertCapture()
        {
            Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
            
            confirmDialog = ConfirmDialog.CreateConfirmDialog(ActiveBrowser, DialogButton.OK);
            confirmDialog.HandlerDelegate = new DialogHandlerDelegate(PrivilegeAlertHandler);
                        
            Manager.DialogMonitor.AddDialog(confirmDialog);

            
        }

 

 public void PrivilegeAlertHandler(IDialog dialog)
        {
            // Simply close the dialog
            dialog.Window.Close();
        }

 

I am currently using version 2016.3.9.28.

 

Thanks,

dan

 

 

0
Boyan Boev
Telerik team
answered on 01 Nov 2016, 04:43 PM
Hi Dan,

I am closing this as it is a duplicate of your support ticket which is resolved now.

Thank you again!

Regards,
Boyan Boev
Telerik by Progress
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
dan
Top achievements
Rank 1
answered on 01 Nov 2016, 04:44 PM
cool. thx!
Tags
General Discussions
Asked by
Rohit
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Rohit
Top achievements
Rank 1
Duncan
Top achievements
Rank 1
Boyan Boev
Telerik team
dan
Top achievements
Rank 1
Share this question
or