예제 #1
0
        public void SecondWindowTestCheckbox()
        {
            Window mainWindow = application.GetWindow("MainWindow");

            //TestStack.White.UIItems.TabItems.TabPage tabInput = mainWindow.Get<White.UIItems.TabItems.TabPage>(SearchCriteria.ByText("Input Controls"));
            //tabInput.Click();
            TestStack.White.UIItems.CheckBox chkSecond = mainWindow.Get <White.UIItems.CheckBox>(SearchCriteria.ByText("A checkbox"));
            chkSecond.Click();
            Thread.Sleep(2000);
            TestStack.White.UIItems.CheckBox tristateChkBox = mainWindow.Get <White.UIItems.CheckBox>(SearchCriteria.ByText("Tristate Checkbox"));
            tristateChkBox.Click();
            Thread.Sleep(2000);
            tristateChkBox.Click();
            Thread.Sleep(2000);
        }
예제 #2
0
 public CheckBoxEvent(CheckBox checkBox)
     : base(checkBox)
 {
     checkState = checkBox.Checked;
 }
        //**************************************************************************************************************************************************************

        public static List<TestStack.White.UIItems.CheckBox> GetAllTableCheckBoxElements(TestStack.White.UIItems.TableItems.Table table, Window window)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);
            List<TestStack.White.UIItems.CheckBox> elements = null;

            try
            {
                Logger.logMessage("GetAllTableCheckBoxElements " + table + "->" + window);

                PropertyCondition tableElementsCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox);
                AutomationElementCollection allTableElements = table.AutomationElement.FindAll(TreeScope.Descendants, tableElementsCondition);

                foreach (AutomationElement item in allTableElements)
                {
                    TestStack.White.UIItems.CheckBox l = new TestStack.White.UIItems.CheckBox(item, window.ActionListener);
                    elements.Add(l);
                }

                Logger.logMessage("GetAllTableCheckBoxElements " + table + "->" + window + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

                return elements;
            }
            catch (Exception e)
            {
                Logger.logMessage("GetAllTableCheckBoxElements " + table + "->" + window + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }
        //**************************************************************************************************************************************************************

        public static void UIA_SelectCheckBoxByName(AutomationElement uiaWindow, Window window, string name, bool state)
        {
            Logger.logMessage("Function call @ :" + DateTime.Now);
            try
            {
                PropertyCondition checkBoxCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox);
                AutomationElementCollection checkBoxes = uiaWindow.FindAll(TreeScope.Descendants, checkBoxCondition);
                foreach (AutomationElement e in checkBoxes)
                {
                    if (e.Current.Name.Equals(name))
                    {
                        TestStack.White.UIItems.CheckBox t = new TestStack.White.UIItems.CheckBox(e, window.ActionListener);
                        if (state)
                            t.Select();
                        break;
                    }
                }
                Thread.Sleep(int.Parse(Execution_Speed));
                Logger.logMessage("UIA_SelectCheckBoxByName " + uiaWindow + "->" + window + "->" + name + "->" + "state" + " - Successful");
                Logger.logMessage("------------------------------------------------------------------------------");

            }
            catch (Exception e)
            {
                Logger.logMessage("UIA_SelectCheckBoxByName " + uiaWindow + "->" + window + "->" + name + "->" + "state" + " - Failed");
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
예제 #5
0
        private static bool AutomateSurroundSettings(Application application)
        {
            // Waiting for form to become visible
            var setupDialog =
                Utility.DefaultOnException(
                    () => application.GetWindow(NVidiaLocalization.NVIDIA_Surround_Caption_NVIDIA_Set_Up_Surround));
            if (setupDialog == null)
            {
                return true; // Control Panel somehow knows the settings
            }

            try
            {
                setupDialog.HideMinimize();
                setupDialog.WaitWhileBusy();
                setupDialog.ShowFocus();
                SplashForm.Instance.Focus();
                System.Windows.Forms.Application.DoEvents();

                var topologyDropdown =
                    Utility.DefaultOnException(() => setupDialog.Get<ComboBox>(SearchCriteria.ByAutomationId("3484")));
                var resolutionDropdown =
                    Utility.DefaultOnException(() => setupDialog.Get<ComboBox>(SearchCriteria.ByAutomationId("3486")));
                var refreshRateDropdown =
                    Utility.DefaultOnException(() => setupDialog.Get<ComboBox>(SearchCriteria.ByAutomationId("3487")));

                setupDialog.HideMinimize();
                setupDialog.WaitWhileBusy();

                // Waiting a little for element to load, if not yet
                var enableButton = setupDialog.GetChildWindowWithControlId<Button>(3493, 5000);

                SplashForm.Instance.Focus();
                System.Windows.Forms.Application.DoEvents();

                var bezel1TextBox = setupDialog.GetChildWindowWithControlId<TextBox>(3506);
                var bezel2TextBox = setupDialog.GetChildWindowWithControlId<TextBox>(3507);
                var bezel3TextBox = setupDialog.GetChildWindowWithControlId<TextBox>(3508);
                var bezel4TextBox = setupDialog.GetChildWindowWithControlId<TextBox>(3509);

                // Lets keep the current display setting before going any further
                Utility.ContinueException(
                    () => Settings.Default.DisplaySettings = DisplaySetting.ArrayToXml(GetDisplaySettings()));

                if (!string.IsNullOrWhiteSpace(Settings.Default.Arrangement))
                {
                    // List of all monitors
                    var displays =
                        setupDialog.GetChildWindowWithControlId<ListView>(3489)
                            .AutomationElement.FindAll(
                                TreeScope.Descendants,
                                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox));

                    if (topologyDropdown != null && Settings.Default.Topology > -1)
                    {
                        var topologyDropdownItems = topologyDropdown.Items;
                        if (topologyDropdownItems.Count > Settings.Default.Topology)
                        {
                            topologyDropdownItems[Settings.Default.Topology].Select();
                            setupDialog.WaitWhileBusy();
                            Mouse.Instance.RestoreLocation();
                            SplashForm.Instance.Focus();
                            System.Windows.Forms.Application.DoEvents();
                        }
                    }

                    foreach (var monitor in Settings.Default.Arrangement.Split('|'))
                    {
                        foreach (AutomationElement display in displays)
                        {
                            var cb = new CheckBox(display, null);
                            if (monitor.ToLower().Trim().Contains(cb.Text.ToLower().Trim()))
                            {
                                Utility.DoTimeout(
                                    () =>
                                    {
                                        Mouse.Instance.Location = cb.Bounds.Location + new Vector(22, 7);
                                        setupDialog.ExecuteAutomationAction(() => Mouse.Instance.Click());
                                        Mouse.Instance.RestoreLocation();
                                        SplashForm.Instance.Focus();
                                        System.Windows.Forms.Application.DoEvents();
                                        return cb.Checked;
                                    });
                                break;
                            }
                        }
                    }

                    if (bezel1TextBox != null && Settings.Default.Bezel1 > -1)
                    {
                        bezel1TextBox.BulkText = Settings.Default.Bezel1.ToString();
                        setupDialog.WaitWhileBusy();
                    }

                    if (bezel2TextBox != null && Settings.Default.Bezel2 > -1)
                    {
                        bezel2TextBox.BulkText = Settings.Default.Bezel2.ToString();
                        setupDialog.WaitWhileBusy();
                    }

                    if (bezel3TextBox != null && Settings.Default.Bezel3 > -1)
                    {
                        bezel3TextBox.BulkText = Settings.Default.Bezel3.ToString();
                        setupDialog.WaitWhileBusy();
                    }

                    if (bezel4TextBox != null && Settings.Default.Bezel4 > -1)
                    {
                        bezel4TextBox.BulkText = Settings.Default.Bezel4.ToString();
                        setupDialog.WaitWhileBusy();
                    }

                    if (resolutionDropdown != null && Settings.Default.Resolution > -1)
                    {
                        var resolutionDropdownItems = resolutionDropdown.Items;
                        if (resolutionDropdownItems.Count > Settings.Default.Resolution)
                        {
                            resolutionDropdownItems[Settings.Default.Resolution].Select();
                            setupDialog.WaitWhileBusy();
                            Mouse.Instance.RestoreLocation();
                            SplashForm.Instance.Focus();
                            System.Windows.Forms.Application.DoEvents();
                        }
                    }

                    if (refreshRateDropdown != null && Settings.Default.RefreshRate > -1)
                    {
                        var refreshRateDropdownItems = refreshRateDropdown.Items;
                        if (refreshRateDropdownItems.Count > Settings.Default.RefreshRate)
                        {
                            refreshRateDropdownItems[Settings.Default.RefreshRate].Select();
                            setupDialog.WaitWhileBusy();
                            Mouse.Instance.RestoreLocation();
                            SplashForm.Instance.Focus();
                            System.Windows.Forms.Application.DoEvents();
                        }
                    }

                    // Let's see if the provided settings are satisfying
                    if (Utility.DoTimeout(
                        () =>
                        {
                            setupDialog.WaitWhileBusy();
                            return enableButton.Enabled;
                        }))
                    {
                        var result = Utility.DoTimeout(
                            () =>
                            {
                                setupDialog.ExecuteAutomationAction(
                                    () => Utility.ContinueException(() => enableButton.Click()));
                                Mouse.Instance.RestoreLocation();
                                System.Windows.Forms.Application.DoEvents();
                                application.WaitWhileBusy();
                                return !enableButton.Enabled
                                       ||
                                       enableButton.Text.ToLower()
                                           .Contains(NVidiaLocalization.NVIDIA_Surround_DisableButton_Disable.ToLower());
                            });
                        Utility.ContinueException(() => setupDialog.Close());
                        if (result)
                        {
                            Settings.Default.Save();
                        }
                        return result;
                    }
                }

                var arrangementPanel = setupDialog.GetChildWindowWithControlId<Button>(3490, 5000);
                if (arrangementPanel == null)
                {
                    throw new Exception(
                        Language.Surround_Arrangement_panel_is_not_accessible_from_our_side_can_t_save_your_settings_);
                }

                // Show the form and lets user to decide what to do
                setupDialog.ShowTopMost();
                Mouse.Instance.Location = setupDialog.Location
                                          + new Vector(setupDialog.Bounds.Width/2, setupDialog.Bounds.Height/2);
                Mouse.Instance.SavePosition();

                while (!setupDialog.IsClosed)
                {
                    try
                    {
                        if (topologyDropdown != null)
                        {
                            Settings.Default.Topology = Methods.SendMessage(topologyDropdown.GetHWnd(), 0x0147, 0, "");
                        }
                        if (resolutionDropdown != null)
                        {
                            Settings.Default.Resolution = Methods.SendMessage(
                                resolutionDropdown.GetHWnd(),
                                0x0147,
                                0,
                                "");
                        }
                        if (refreshRateDropdown != null)
                        {
                            Settings.Default.RefreshRate = Methods.SendMessage(
                                refreshRateDropdown.GetHWnd(),
                                0x0147,
                                0,
                                "");
                        }

                        Utility.ContinueException(
                            () =>
                            {
                                Settings.Default.Bezel1 = (!string.IsNullOrWhiteSpace(bezel1TextBox?.Text))
                                    ? bezel1TextBox.Text.TryParseIntOrDefault()
                                    : 0;
                                Settings.Default.Bezel2 = (!string.IsNullOrWhiteSpace(bezel2TextBox?.Text))
                                    ? bezel2TextBox.Text.TryParseIntOrDefault()
                                    : 0;
                                Settings.Default.Bezel3 = (!string.IsNullOrWhiteSpace(bezel3TextBox?.Text))
                                    ? bezel3TextBox.Text.TryParseIntOrDefault()
                                    : 0;
                                Settings.Default.Bezel4 = (!string.IsNullOrWhiteSpace(bezel4TextBox?.Text))
                                    ? bezel4TextBox.Text.TryParseIntOrDefault()
                                    : 0;
                            });

                        Utility.ContinueException(
                            () =>
                            {
                                if (!arrangementPanel.IsOffScreen)
                                {
                                    Settings.Default.Arrangement = string.Join(
                                        "|",
                                        arrangementPanel.AutomationElement.FindAll(
                                            TreeScope.Children,
                                            Condition.TrueCondition)
                                            .Cast<AutomationElement>()
                                            .Select(el => new Panel(el, null))
                                            .OrderBy(panel => panel.Bounds.Right)
                                            .ThenBy(panel => panel.Bounds.Bottom)
                                            .Select(panel => panel.Text));
                                }
                            });

                        setupDialog.WaitWhileBusy();
                        if (
                            enableButton.Text.ToLower()
                                .Contains(NVidiaLocalization.NVIDIA_Surround_DisableButton_Disable.ToLower()))
                        {
                            Settings.Default.Save();
                            setupDialog.Close();
                            System.Windows.Forms.Application.DoEvents();
                            setupDialog.WaitWhileBusy();
                            return true;
                        }

                        Thread.Sleep(100);
                        setupDialog.WaitWhileBusy();
                        System.Windows.Forms.Application.DoEvents();
                    }
                    catch (Exception)
                    {
                        break;
                    }
                }
                Utility.ContinueException(
                    () =>
                    {
                        setupDialog.Close();
                        setupDialog.WaitWhileBusy();
                    });
                Settings.Default.Reload();
                return false;
            }
            catch (Exception)
            {
                setupDialog.Close();
                setupDialog.WaitWhileBusy();
                throw;
            }
        }
예제 #6
0
 public void GivenIHaveSelectedRememberMeCheckbox()
 {
     rememberMeCheckBox = loginWindow.Get<CheckBox>(SearchCriteria.ByClassName("CheckBox"));
     if (!rememberMeCheckBox.Checked)
         rememberMeCheckBox.Click();
 }