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

Telerik can't handle more than 1 dialogs in Silverlight

1 Answer 41 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tuan
Top achievements
Rank 1
Tuan asked on 14 May 2012, 05:10 AM
Hi telerik,

I'm automation an Silverlight app that invoke a dialogs that looks like windows dialog (see attach image)

So I used this code and it works but when it handle the second dialog, it just stop there and it doesn't click the OK button.
Please help me figure this out.
Thanks

try
{
    Button btnRemoveDashboard = GlobalObject.SILVERLIGHTAPP.Find.ByName<Button>("btnRemoveDashboard");
    GlobalObject.MANAGER.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
 
    GenericDialog altDlg = new GenericDialog(SM2Utilities.GlobalObject.BROWSER, "Close" + strDBName, true, "OK", "Are you sure you want to remove this dashboard and all of its panels?");
    altDlg.HandlerDelegate = MyCustomAlertHandler;
    altDlg.DismissButton = DialogButton.OK;
    GlobalObject.MANAGER.DialogMonitor.AddDialog(altDlg);
    GlobalObject.MANAGER.DialogMonitor.Start();
    btnRemoveDashboard.User.Click();
 
    altDlg.WaitUntilHandled(5000);
 
    GlobalObject.MANAGER.DialogMonitor.RemoveDialog(altDlg);
    GlobalObject.MANAGER.DialogMonitor.Stop();
    GlobalObject.MANAGER.Dispose();
}
catch (Exception)
{
}
 
 
public static void MyCustomAlertHandler(IDialog dialog)
{
            Window okButton = WindowManager.FindWindowRecursively(dialog.Window.Handle, "OK", false, 0);
 
            GlobalObject.MANAGER.Desktop.Mouse.Click(MouseClickType.LeftClick, okButton.Rectangle);
            dialog.HandleCount++;
}

1 Answer, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 14 May 2012, 07:44 PM
Hello Tuan,

Are you creating a GenericDialog and adding it to the monitor for each dialog to be handled? The following code worked for me against a public site with an Alert dialog:

[TestMethod]
public void TwoAlertsCustom()
{
    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
 
    GenericDialog ad = new GenericDialog(ActiveBrowser, "Message", true);
    ad.HandlerDelegate = MyCustomAlertHandler;
    ad.DismissButton = DialogButton.OK;
 
    GenericDialog ad2 = new GenericDialog(ActiveBrowser, "Message", true);
    ad.HandlerDelegate = MyCustomAlertHandler;
    ad.DismissButton = DialogButton.OK;
 
    Manager.DialogMonitor.AddDialog(ad);
    Manager.DialogMonitor.AddDialog(ad2);
    Manager.DialogMonitor.Start();
 
    ArtOfTest.WebAii.Core.Browser frSub = ActiveBrowser.Frames["view"];
    frSub.RefreshDomTree();
 
    HtmlInputButton show = frSub.Find.ByExpression<HtmlInputButton>("value=Show alert box");
    show.Click();
    ad.WaitUntilHandled(5000);
 
    show.Click();
    ad2.WaitUntilHandled(5000);
 
    Manager.DialogMonitor.RemoveDialog(ad);
    Manager.DialogMonitor.RemoveDialog(ad2);
    Manager.DialogMonitor.Stop();
    //Manager.Dispose();
}
 
public static void MyCustomAlertHandler(IDialog dialog)
{
    Window okButton = WindowManager.FindWindowRecursively(dialog.Window.Handle, "OK", false, 0);
    Manager.Current.Desktop.Mouse.Click(MouseClickType.LeftClick, okButton.Rectangle);
    dialog.HandleCount++;
}


Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Tuan
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Share this question
or