Search code examples
c#internet-explorer-9integration-testingwatin

Issue with WatiN and IE9 regarding multiple dialogs


I am using the latest 4/12/2011 build of WatiN (2.1.0.1196).

I have an aspx page loaded into an IFrame in Dynamics Crm. There is a button on the page that opens and modal dialog form. So far most of the test cases are working correctly with WatiN except for a specific use case.

If a specific combination of controls are set on the modal dialog, a confirm dialog box will pop up after the user presses the submit button. If the user selects ok it will continue the submit execution, if cancel it will return back to the modal dialog. The test times out when this confirm dialog box appears. I cant seem to get the handler setup right to catch the confirm dialog.

Here is a test method I have been trying:

    [TestMethod]
    public void Add_New_Post_To_Record_Public_NotOnBehalf_NoSub_No_Notifications()
    {
        using (var browser = new IE("URL to the IFRAME"))
        {                
            var approveConfirmDialog = ReturnDialogHandler.CreateInstance(); 
            var confirmCode = Guid.NewGuid();

           //logon to CRM
            logonToADFS(browser);

            var recordPage = browser.Page<DiscussionRecordpage>();
            recordPage.CreateNewPostButton.ClickNoWait();

            HtmlDialog dialog = browser.HtmlDialog(Find.ByTitle("New Post"));
            var messageText = dialog.TextField(Find.ByClass("required"));
            messageText.TypeText("Type some text. Confirmation code: " + confirmCode.ToString());

            var button = dialog.Button(Find.ByClass("submit-button"));

            using (new UseDialogOnce(browser.DialogWatcher, approveConfirmDialog))
            {
                button.ClickNoWait();
                approveConfirmDialog.WaitUntilExists();
                approveConfirmDialog.OKButton.Click();
            }
            browser.WaitForComplete();

            Assert.IsTrue(browser.ContainsText(confirmCode.ToString())); 
        }
    }

I have tried a couple different variations all with the same result. I assume that I need to use the ReturnDialogHanlder.CreateInstance() method for IE9 compatibility, but the standard ConfirmDialogHandler did not seem to work either. Honestly, I don’t know if I am using the dialog handler correctly in this case, but I can click the ok buttons on other confirm dialogs that spawn from buttons on other pages. This is a bit unique since it is spawning from a modal dialog instead of a page.

I also tried using this custom handler (C# WatiN - Add an AlertDialogHandler to click ok button on every Alert dialog window) with no results.

Thanks in advance.


Solution

  • It's too hard. I suggest a workaround: most of the case, you could close the dialog using keyboard. so you could sendkeys to close the dialog. Just FYI.