Exemplo n.º 1
0
        public void TogglePatternTest()
        {
            using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL main.cpl ,2"))
            {
                // Find a well-known checkbox
                AutomationElement checkbox = host.Element.FindFirst(TreeScope.Subtree,
                                                                    new PropertyCondition(AutomationElement.AutomationIdProperty, "109"));
                Assert.IsNotNull(checkbox);

                TogglePattern toggle        = (TogglePattern)checkbox.GetCurrentPattern(TogglePattern.Pattern);
                ToggleState   originalState = toggle.Current.ToggleState;
                toggle.Toggle();
                // Slight wait for effect
                System.Threading.Thread.Sleep(100 /* ms */);
                ToggleState currentState = toggle.Current.ToggleState;
                Assert.AreNotEqual(originalState, currentState);

                // Put it back
                while (currentState != originalState)
                {
                    toggle.Toggle();
                    System.Threading.Thread.Sleep(100 /* ms */);
                    currentState = toggle.Current.ToggleState;
                }
            }
        }
Exemplo n.º 2
0
 protected override void ProcessRecord()
 {
     if (UIElement != null)
     {
         UIElement.SetFocus();
         TogglePattern tp = GetPattern.GetTogglePattern(UIElement);
         if ((!On.ToBool() && !Off.ToBool()) || (On.ToBool() && Off.ToBool()))
         {
             tp.Toggle();
         }
         else if (Off.ToBool())
         {
             while (tp.Current.ToggleState != ToggleState.Off && Timeout > 0)
             {
                 tp.Toggle();
                 Thread.Sleep(1000);
                 Timeout = Timeout - 1000;
             }
         }
         else if (On.ToBool())
         {
             while (tp.Current.ToggleState != ToggleState.On && Timeout > 0)
             {
                 tp.Toggle();
                 Thread.Sleep(1000);
                 Timeout = Timeout - 1000;
             }
         }
     }
 }
Exemplo n.º 3
0
        public static void SetChecked(this AutomationElement parent, string name, bool value)
        {
            AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

            if (box == null)
            {
                throw new Exception("CheckBox '" + name + "' not found");
            }
            if (!box.Current.IsEnabled)
            {
                throw new Exception("CheckBox '" + name + "' is not enabled");
            }

            TogglePattern p = (TogglePattern)box.GetCurrentPattern(TogglePattern.Pattern);

            if (value)
            {
                if (p.Current.ToggleState != ToggleState.On)
                {
                    p.Toggle();
                }
            }
            else
            {
                if (p.Current.ToggleState == ToggleState.On)
                {
                    p.Toggle();
                }
            }
        }
        public void SetUnselected()
        {
            Assert.IsTrue((bool)Element.GetCurrentPropertyValue(AutomationElement.IsTogglePatternAvailableProperty), "Element is not a check box");
            TogglePattern pattern = (TogglePattern)Element.GetCurrentPattern(TogglePattern.Pattern);

            if (pattern.Current.ToggleState != ToggleState.Off)
            {
                pattern.Toggle();
            }
            if (pattern.Current.ToggleState != ToggleState.Off)
            {
                pattern.Toggle();
            }
            Assert.AreEqual(pattern.Current.ToggleState, ToggleState.Off, "Could not toggle " + Name + " to Off.");
        }
Exemplo n.º 5
0
        private static void executePattern(AutomationElement subject, AutomationPattern inPattern)
        {
            switch (inPattern.ProgrammaticName)
            {
            case "InvokePatternIdentifiers.Pattern":
            {
                InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern);
                invoke.Invoke();
                break;
            }

            case "SelectionItemPatternIdentifiers.Pattern":
            {
                SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern);
                select.Select();
                break;
            }

            case "TogglePatternIdentifiers.Pattern":
            {
                TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern);
                toggle.Toggle();
                break;
            }

            case "ExpandCollapsePatternIdentifiers.Pattern":
            {
                ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                exColPat.Expand();
                break;
            }
            }
        }
Exemplo n.º 6
0
 public void Toggle()
 {
     STAHelper.Invoke(
         delegate() {
         TogglePattern.Toggle();
     }
         );
 }
        public static void Toggle(this AutomationElement Control)
        {
            //check if the buttonControl is indeed a handle to a button-based control
            TogglePattern togglePattern = ValidateControlForTogglePattern(Control);

            //click the button control
            togglePattern.Toggle();
        }
Exemplo n.º 8
0
        public void AutoResize_Default()
        {
            try
            {
                Console.WriteLine("starting test....");
                AutomationElement autoResize        = GetElement("chkAutoResize");
                AutomationElement txtWidthReadOnly  = GetElement("txtWidthReadOnly");
                AutomationElement txtWidthWrite     = GetElement("txtWidthWrite");
                AutomationElement txtHeightReadOnly = GetElement("txtHeightReadOnly");
                AutomationElement txtHeightWrite    = GetElement("txtHeightWrite");

                TogglePattern toggle = (TogglePattern)autoResize.GetCurrentPattern(TogglePattern.Pattern);

                //verify is off at startup
                Assert.AreEqual(ToggleState.Off, toggle.Current.ToggleState);

                //verify widthRO is not visible and widthWrite is
                Assert.IsFalse((bool)txtWidthWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsTrue((bool)txtWidthReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify heightRO is not visible and heightWrite is
                Assert.IsFalse((bool)txtHeightWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsTrue((bool)txtHeightReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //can't check canvas size now need to refactor

                //verify the value
                ValuePattern txtWidthValue  = (ValuePattern)txtWidthWrite.GetCurrentPattern(ValuePattern.Pattern);
                ValuePattern txtHeightValue = (ValuePattern)txtHeightWrite.GetCurrentPattern(ValuePattern.Pattern);
                int          width          = Int32.Parse(txtWidthValue.Current.Value);
                int          height         = Int32.Parse(txtHeightValue.Current.Value);

                Assert.AreEqual(DEFAULT_WIDTH, width);
                Assert.AreEqual(DEFAULT_HEIGHT, height);

                toggle.Toggle();

                //verify widthRO is visible and widthWrite is not
                Assert.IsTrue((bool)txtWidthWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsFalse((bool)txtWidthReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify heightRO is visible and heightWrite is not
                Assert.IsTrue((bool)txtHeightWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsFalse((bool)txtHeightReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify the value
                width  = Int32.Parse(txtWidthReadOnly.Current.Name);
                height = Int32.Parse(txtHeightReadOnly.Current.Name);
                Assert.AreEqual(DEFAULT_WIDTH, width);
                Assert.AreEqual(DEFAULT_HEIGHT, height);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception Caught:");
                Console.WriteLine(e.Message);
                Assert.Fail();
            }
        }
        // RopModifyPermissions RopGetPermissionsTable
        public void ModifyFolderPermissions()
        {
            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = oApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder   = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName = folder.Parent.Name;

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Get Folder Tab and select it
            Condition            cd_RibbonTabs      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Folder"));
            AutomationElement    item_RibbonTabs    = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300);
            SelectionItemPattern Pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern);

            Pattern_RibbonTabs.Select();

            // Get "Folder Permissions" and select it
            Condition         cd_FolderPermissions           = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Folder Permissions"));
            AutomationElement item_FolderPermissions         = Utilities.WaitForElement(window_outlook, cd_FolderPermissions, TreeScope.Descendants, 10);
            InvokePattern     clickPattern_FolderPermissions = (InvokePattern)item_FolderPermissions.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPermissions.Invoke();

            // Get "Inbox Properties" window
            var condition_permission = new PropertyCondition(AutomationElement.NameProperty, "Inbox Properties");
            var window_FolderProp    = Utilities.WaitForElement(window_outlook, condition_permission, TreeScope.Children, 10);

            // Get and select "Create items"
            Condition         cd_write      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox), new PropertyCondition(AutomationElement.NameProperty, "Edit all"));
            AutomationElement item_write    = Utilities.WaitForElement(window_FolderProp, cd_write, TreeScope.Descendants, 10);
            TogglePattern     Pattern_write = (TogglePattern)item_write.GetCurrentPattern(TogglePattern.Pattern);

            Pattern_write.Toggle();

            // Click OK in Microsoft Outlook dialog box
            var           condition_Dailog      = new PropertyCondition(AutomationElement.NameProperty, "Microsoft Outlook");
            var           window_Dailog         = Utilities.WaitForElement(window_FolderProp, condition_Dailog, TreeScope.Children, 10);
            var           condition_DailogOK    = new PropertyCondition(AutomationElement.AutomationIdProperty, "6");
            var           item_DailogOK         = Utilities.WaitForElement(window_Dailog, condition_DailogOK, TreeScope.Children, 10);
            InvokePattern clickPattern_DailogOK = (InvokePattern)item_DailogOK.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_DailogOK.Invoke();

            // Click OK in "Inbox Properties" window
            var           condition_FolderPropOK        = new PropertyCondition(AutomationElement.AutomationIdProperty, "1");
            var           item_FolderPropertyOK         = Utilities.WaitForElement(window_FolderProp, condition_FolderPropOK, TreeScope.Children, 10);
            InvokePattern clickPattern_FolderPropertyOK = (InvokePattern)item_FolderPropertyOK.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPropertyOK.Invoke();

            bool result = MessageParser.ParseMessage();

            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
Exemplo n.º 10
0
        private void TogglePatternController()
        {
            TogglePattern togglePattern = (TogglePattern)PatternObject;

            if (MethodType == 1)
            {
                togglePattern.Toggle();
            }
        }
Exemplo n.º 11
0
        public static void Check(AutomationElement element)
        {
            // element.SetFocus();
            //SendKeys.SendWait(" ");

            TogglePattern togglePattern = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

            togglePattern.Toggle();
        }
Exemplo n.º 12
0
        // This will bring the window to front if it is in normal or maximized state. Using Win32 Click instead
        public static void ChangeCheckBoxState(AutomationElement element)
        {
            TogglePattern targetInvokePattern = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

            if (targetInvokePattern == null)
            {
                return;
            }
            targetInvokePattern.Toggle();
        }
 /// <summary>
 /// Sets state of toggle control
 /// </summary>
 /// <param name="control">The UI Automation element</param>
 /// <param name="toggleState">The current <see cref="System.Windows.Automation.ToggleState"/>ToggleState</param>
 internal static void SetToggleState(AutomationElement control, ToggleState toggleState)
 {
     /* Only need to change it if it needs-a-changin' */
     if (GetToggleState(control) != toggleState)
     {
         TogglePattern pattern = (TogglePattern)control.GetCurrentPattern(TogglePattern.Pattern);
         pattern.Toggle();
     }
     ValueVerifier <ToggleState, ToggleState> .Verify(toggleState, GetToggleState(control));
 }
Exemplo n.º 14
0
 public void SetCheck(int hwnd, bool check)
 {
     if (IsChecked(hwnd) != check)
     {
         AutomationElement element = Find(hwnd);
         TogglePattern     toggle  = element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
         logger.Debug("");
         toggle.Toggle();
     }
 }
Exemplo n.º 15
0
        public void Toggle(bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Toggle {0}.", this.NameAndType));
            }

            TogglePattern tp = (TogglePattern)element.GetCurrentPattern(TogglePattern.Pattern);

            tp.Toggle();
        }
Exemplo n.º 16
0
        public void SetItemCheckedStatus(string treepath, bool Checked)
        {
            AutomationElement e = _openitem(this._condition.AutomationElement, treepath, false);

            try
            {
                TogglePattern mexpand = (TogglePattern)e.GetCurrentPattern(TogglePattern.Pattern);
                if (Checked && mexpand.Current.ToggleState == ToggleState.Off)
                {
                    mexpand.Toggle();
                }
                else if (!Checked && mexpand.Current.ToggleState == ToggleState.On)
                {
                    mexpand.Toggle();
                }
            }
            catch
            {
                ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation);
            }
        }
Exemplo n.º 17
0
        //</Snippet1100>

        ///--------------------------------------------------------------------
        /// <summary>
        /// Handles the Toggle click event.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        ///--------------------------------------------------------------------
        void Toggle_Click(object sender, RoutedEventArgs e)
        {
            Button        clientButton = sender as Button;
            TogglePattern t            = clientButton.Tag as TogglePattern;

            if (t == null)
            {
                return;
            }
            t.Toggle();
            statusText.Text = "Element toggled " + t.Current.ToggleState.ToString();
        }
Exemplo n.º 18
0
        public void ToggleTest()
        {
            TogglePattern pattern = (TogglePattern)checkBox1Element.GetCurrentPattern(TogglePattern.Pattern);

            Assert.AreEqual(ToggleState.Off, pattern.Current.ToggleState, "ToggleState before Toggle");
            pattern.Toggle();
            // TODO: Enable this after resolving at-spi-sharp threading/MainLoop issues
            if (!Atspi)
            {
                Assert.AreEqual(ToggleState.On, pattern.Current.ToggleState, "ToggleState after Toggle");
            }
        }
Exemplo n.º 19
0
        // </Snippet101>

        // <Snippet102>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Calls the TogglePattern.Toggle() method for an associated
        /// automation element.
        /// </summary>
        /// <param name="togglePattern">
        /// The TogglePattern control pattern obtained from
        /// an automation element.
        /// </param>
        ///--------------------------------------------------------------------
        private void ToggleElement(TogglePattern togglePattern)
        {
            try
            {
                togglePattern.Toggle();
            }
            catch (InvalidOperationException)
            {
                // object is not able to perform the requested action
                return;
            }
        }
Exemplo n.º 20
0
        public static bool toggleCheckbox(AutomationElement ae)
        {
            object temp;

            if (ae.TryGetCurrentPattern(TogglePattern.Pattern, out temp))
            {
                TogglePattern pattern = temp as TogglePattern;
                pattern.Toggle();
                return(true);
            }
            return(false);
        }
Exemplo n.º 21
0
        public void Interact()
        {
            // For debugging purposes we enlight the control
            // choosen so we can easily spot it.
            //DBGMark();

            // If the element we have is from UIAutomation, simply interact with it.
            object objPattern;

            if (AutoElementRef != null && AutoElementRef.Current.ControlType == System.Windows.Automation.ControlType.Button && AutoElementRef.TryGetCurrentPattern(InvokePattern.Pattern, out objPattern))
            {
                System.Windows.Point pt = new System.Windows.Point();
                if (AutoElementRef.TryGetClickablePoint(out pt))
                {
                    System.Windows.Forms.Cursor.Position = new Point((int)pt.X + 1, (int)pt.Y + 1);
                    LeftClick();
                }
                else
                {
                    // NOTE! The following approach won't work for some strange UIs (probably bugged). We use the classic way of sendkeys to solve this problem once for all
                    // For buttons
                    InvokePattern invPattern = objPattern as InvokePattern;
                    invPattern.Invoke();
                }
            }
            else if (AutoElementRef != null && AutoElementRef.Current.ControlType == System.Windows.Automation.ControlType.RadioButton && AutoElementRef.TryGetCurrentPattern(SelectionItemPatternIdentifiers.Pattern, out objPattern))
            {
                // Radios
                SelectionItemPattern invPattern = objPattern as SelectionItemPattern;
                invPattern.Select();
            }
            else if (AutoElementRef != null && AutoElementRef.Current.ControlType == System.Windows.Automation.ControlType.CheckBox && AutoElementRef.TryGetCurrentPattern(TogglePatternIdentifiers.Pattern, out objPattern))
            {
                // Checkboxes
                TogglePattern invPattern = objPattern as TogglePattern;
                invPattern.Toggle();
            }
            else
            {
                // Let's assume a very simple thing: interaction = mouseclick. We click in the middle of the control.
                // This won't work for combobox, but will work for mostly any Checkbox, radio button, hyperlink and custom buttons.
                // Calculate the center of control
                int x = PositionScreenRelative.Width / 2 + PositionScreenRelative.X;
                int y = PositionScreenRelative.Height / 2 + PositionScreenRelative.Y;

                System.Windows.Forms.Cursor.Position = new Point(x, y);
                LeftClick();
            }
        }
Exemplo n.º 22
0
 public void Check(bool value)
 {
     this.PrepareForReplay();
     try
     {
         TogglePattern t = (TogglePattern)this._condition.AutomationElement.GetCurrentPattern(TogglePattern.Pattern);
         if (t.Current.ToggleState == ToggleState.Off)
         {
             if (value)
             {
                 t.Toggle();
             }
         }
         else
         {
             if (!value)
             {
                 t.Toggle();
             }
         }
     }
     catch
     { }
 }
Exemplo n.º 23
0
        public void Z_EventTest()
        {
            int eventCount = 0;
            AutomationPropertyChangedEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationPropertyChangedEventHandler(checkBox1Element, TreeScope.Element, handler,
                                                        TogglePattern.ToggleStateProperty);

            TogglePattern pattern = (TogglePattern)checkBox1Element.GetCurrentPattern(TogglePattern.Pattern);

            pattern.Toggle();
            //We should expect an AutomationPropertyChangedEvent here,
            //But since no such event fired on Windows Winforms,
            //then we assert no event fired here
            int expectedEventCount = (Atspi? 1: 0);

            Assert.AreEqual(expectedEventCount, eventCount, "ToggleState changed event");
        }
Exemplo n.º 24
0
        public static void Toggle(AutomationElement element, bool toggle)
        {
            TogglePattern currentPattern = AutomationPatternHelper.GetTogglePattern(element);
            ToggleState   indeterminate  = ToggleState.Indeterminate;

            if (toggle == true)
            {
                indeterminate = ToggleState.On;
            }
            else if (toggle == false)
            {
                indeterminate = ToggleState.Off;
            }
            while (currentPattern.Current.ToggleState != indeterminate)
            {
                currentPattern.Toggle();
            }
        }
Exemplo n.º 25
0
        public static void ToggleCheckBox(AutomationElement chk, ToggleState TargetState)
        {
            TogglePattern togglePattern = chk.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

            int i = 0;

            while (i < 3) // 3 state, on, off, indeter
            {
                if (TargetState != togglePattern.Current.ToggleState)
                {
                    ++i;
                    togglePattern.Toggle();
                    UtilSys.Sleep(50);
                }
                if (TargetState == togglePattern.Current.ToggleState)
                {
                    return;
                }
            }
        }
Exemplo n.º 26
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        internal void patternToggle(Type expectedException, CheckType checkType)
        {
            string call = "Toggle()";

            try
            {
                _pattern.Toggle();
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                {
                    throw;
                }

                TestException(expectedException, actualException, call, checkType);
                return;
            }
            TestNoException(expectedException, call, checkType);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 设置复选框元素选择状态
        /// </summary>
        /// <param name="element">复选框元素</param>
        /// <param name="statu">选择状态</param>
        public static void CF_SetCheckBoxStatu(AutomationElement element, bool statu)
        {
            if (element != null && element.Current.ControlType == ControlType.CheckBox)
            {
                try
                {
                    if (element.TryGetCurrentPattern(TogglePattern.Pattern, out object pattern))
                    {
                        TogglePattern togglePattern = pattern as TogglePattern;
                        ToggleState   toggleState   = statu ? ToggleState.On : ToggleState.Off;

                        if (togglePattern.Current.ToggleState != toggleState)
                        {
                            togglePattern.Toggle();
                        }
                    }
                }
                catch { }
            }
        }
Exemplo n.º 28
0
        public static void executePattern(AutomationElement subject, AutomationPattern inPattern)
        {
            try
            {
                switch (inPattern.ProgrammaticName)
                {
                case "InvokePatternIdentifiers.Pattern":
                {
                    InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern);
                    invoke.Invoke();
                    break;
                }

                case "SelectionItemPatternIdentifiers.Pattern":
                {
                    SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern);
                    select.Select();
                    break;
                }

                case "TogglePatternIdentifiers.Pattern":
                {
                    TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern);
                    toggle.Toggle();
                    break;
                }

                case "ExpandCollapsePatternIdentifiers.Pattern":
                {
                    ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern);
                    exColPat.Expand();
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                //ignore for now issue with infragistics elements not getting proper states
                //throw;
            }
        }
        /// <summary>
        /// Close checkin pane in opening word
        /// </summary>
        /// <param name="filename">file name</param>
        /// <param name="keepCheckOut">Bool value indicate whether to keep check out when do checkIn</param>
        public static void CloseCheckInPane(string filename, bool keepCheckOut)
        {
            var               desktop       = AutomationElement.RootElement;
            Condition         Con_Document  = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, filename + ".docx - Word"));
            AutomationElement item_Document = desktop.FindFirst(TreeScope.Children, Con_Document);
            Condition         Con_Checkin   = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, "Check In"));
            AutomationElement item_Checkin  = WaitForElement(item_Document, Con_Checkin, TreeScope.Children, true);

            if (keepCheckOut)
            {
                Condition         Con_CheckBox     = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox), new PropertyCondition(AutomationElement.NameProperty, "Keep the document checked out after checking in this version."));
                AutomationElement item_CheckBox    = item_Checkin.FindFirst(TreeScope.Descendants, Con_CheckBox);
                TogglePattern     Pattern_CheckBox = (TogglePattern)item_CheckBox.GetCurrentPattern(TogglePattern.Pattern);
                Pattern_CheckBox.Toggle();
            }

            Condition         Con_Yes     = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "OK"));
            AutomationElement item_Yes    = item_Checkin.FindFirst(TreeScope.Descendants, Con_Yes);
            InvokePattern     Pattern_Yes = (InvokePattern)item_Yes.GetCurrentPattern(InvokePattern.Pattern);

            Pattern_Yes.Invoke();
        }
Exemplo n.º 30
0
        public void AutoResize_Toggle()
        {
            try
            {
                Console.WriteLine("starting test....");
                AutomationElement autoResize        = GetElement("chkAutoResize");
                AutomationElement txtWidthReadOnly  = GetElement("txtWidthReadOnly");
                AutomationElement txtWidthWrite     = GetElement("txtWidthWrite");
                AutomationElement txtHeightReadOnly = GetElement("txtHeightReadOnly");
                AutomationElement txtHeightWrite    = GetElement("txtHeightWrite");

                TogglePattern toggle = (TogglePattern)autoResize.GetCurrentPattern(TogglePattern.Pattern);

                toggle.Toggle();

                //verify widthRO is visible and widthWrite is not
                Assert.IsTrue((bool)txtWidthWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsFalse((bool)txtWidthReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify heightRO is visible and heightWrite is not
                Assert.IsTrue((bool)txtHeightWrite.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));
                Assert.IsFalse((bool)txtHeightReadOnly.GetCurrentPropertyValue(AutomationElement.IsOffscreenProperty));

                //verify the value
                int width  = Int32.Parse(txtWidthReadOnly.Current.Name);
                int height = Int32.Parse(txtHeightReadOnly.Current.Name);
                Assert.AreEqual(DEFAULT_WIDTH, width);
                Assert.AreEqual(DEFAULT_HEIGHT, height);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception Caught:");
                Console.WriteLine(e.Message);
                Assert.Fail();
            }
        }