how to get and verify the message show in the msgbox.

2 posts, 0 answers
  1. Jack
    Jack avatar
    1 posts
    Member since:
    Jul 2010

    Posted 21 Jul 2010 Link to this post

    Is there any API we can use to get the  message display on the messagebox.eg:when user log in to the system the usernam is null,click the log in button ,the warnning message like "please input username".
  2. Kiran
    Kiran avatar
    56 posts
    Member since:
    Dec 2008

    Posted 21 Jul 2010 Link to this post

    Hi Jack,

    Try the below code and let me know if it is working.

    I am having a silverlight application. When i click a button it will dispaly a message box with caption "My Message" and text

    "Hello World!!!!!!".
    Please make sure to give Thread.Sleep() after the button click.

    [TestMethod]
            public void MessageBoxTest()
            {
      
                Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
                ActiveBrowser.NavigateTo("http://localhost:2463/SampleApplicationTestPage.aspx");
      
                  
                // Get an instance of the running Silverlight Application.
                SilverlightApp  CurrentApplication = ActiveBrowser.SilverlightApps()[0];
                //To activate the silverlight control
                CurrentApplication.Desktop.Mouse.Click(MouseClickType.LeftClick, CurrentApplication.Bounds);
      
                Button btnShowMessageBox = CurrentApplication.Find.ByName<Button>("btnShowMessageBox");
                btnShowMessageBox.User.Click();
      
                Thread.Sleep(2000);
                Window msgBox = null;            
      
                WindowManager winManager = new WindowManager();
                winManager.GetWindows();
                foreach (Window win in winManager.Items)
                {               
                    if (win.Caption.Contains("My Message"))
                        msgBox = win; 
                }
      
      
                if (msgBox != null)
                {
                   var label= msgBox.AllChildren.OfType<Window>().Where(w => w.ClassName == "Static");
                   if (label.FirstOrDefault().Caption == "Hello World!!!!!!!!")
                   {
                       msgBox.Close();
                   }
                }
                 
                Thread.Sleep(4000);
      
                
                 
            }

    Thanks
    Kiran
Back to Top