unresponsive checkbox

Mar 25, 2010 at 1:53 PM

Hi,

I'm evaluating White for UI testing. For doing that I'm developing some test applications, so far I had no success with White.

My first sample application (called WhiteExample) consist of a WPF windows with one checkbox and a button (really simple). In this application the button is disabled when the checkbox is checked. Therefore I built a WPF test application to check this behavior as follows:

 

using System;
using System.Windows;
using System.Windows.Threading;
using System.Threading;
// for White
using White.Core;
using White.Core.InputDevices;
using White.Core.Factory;
using White.Core.UIItems;
using White.Core.UIItems.Finders;



namespace WhiteTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private delegate void SetMessageCallback(string message);

        private const string path = @"..\..\..\WhiteExample\bin\Debug\WhiteExample.exe";

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Thread automateThread = new Thread(new ThreadStart(Automate));
            automateThread.Start();
        }

        private void Automate()
        {
            LogMessage("Searching for application... ");
            White.Core.Application application = White.Core.Application.Launch(path);
            if (application != null)
            {
                LogMessage("OK " + Environment.NewLine);
                LogMessage("Searching for window... ");
                White.Core.UIItems.WindowItems.Window window = application.GetWindow("AutomatedWindow", InitializeOption.NoCache);
                if (window != null)
                {
                    LogMessage("OK " + Environment.NewLine);
                    LogMessage("Searching for the Checkbox... ");
                    CheckBox chkbox = window.Get<CheckBox>(SearchCriteria.ByAutomationId("checkBox1"));
                    if (chkbox != null)
                    {
                        LogMessage("OK " + Environment.NewLine);
                        LogMessage("Checking the Checkbox... ");
                        chkbox.Click();
                        if(chkbox.Checked)
                            LogMessage("OK " + Environment.NewLine);
                        else
                            LogMessage("ERROR!! " + Environment.NewLine);

                        LogMessage("Searching for the button... ");
                        Button btn = window.Get<Button>(SearchCriteria.ByAutomationId("button1"));
                        if (btn != null)
                        {
                            LogMessage("OK " + Environment.NewLine);
                            LogMessage("Checking if the button is disabled...");
                            if (btn.Enabled)
                            {
                                LogMessage("NO!!! " + Environment.NewLine);
                            }
                            else
                                LogMessage("YES!!! " + Environment.NewLine);
                        }
                        else 
                            WriteLogError();
                    }
                    else 
                        WriteLogError();
                }
                else
                    WriteLogError();
                
                // Close the application
                application.Kill();
            }
            else
            {
                WriteLogError();
            }
        }

        private void DisplayLogMessage(string message)
        {
            textBlock1.Text += message;
        }

        private void LogMessage(string message)
        {
            this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new SetMessageCallback(DisplayLogMessage), message);
        }

        private void WriteLogError()
        {
            LogMessage("ERROR." + Environment.NewLine);
        }
    }
}

 

As you can see this test application launch the sample application (WhiteExample) and check some of its UI elements, the LogMessage function puts the message into a TextBlock.

The problem is that the method

chkbox.Click();

seems not working since the checkbox is never checked.

What am I doing wrong?

 

Thank you very much.

 

Regards,

Víctor

 

 

Mar 26, 2010 at 12:34 PM

Can you check if the check box is enabled?

Mar 29, 2010 at 11:30 AM

Hi deepban74,

yes the checkbox is enabled :S

Coordinator
Apr 10, 2010 at 11:08 AM

Can you check by clicking at the center of bounds of checkbox? Or else you can use State property to change the state of the checkbox.