public void MatchSingleOption_WithMatchingValue_ReturnsResult()
        {
            var pattern = new ValuePattern<int, long>()
                .If(4, x => 5);

            var result = pattern.Match(4);
            Assert.Equal(5, result);
        }
        public void MatchMultipleOptions_WithUnmatched_Throws()
        {
            var pattern = new ValuePattern<int, long>()
                .If(4, x => 5)
                .If(6, x => 7)
                .If(8, x => 42);

            Assert.Throws<InvalidOperationException>(() => pattern.Match(2));
        }
        public void MatchWithDefault_WithUnmatched_ReturnsDefault()
        {
            var pattern = new ValuePattern<string, string>()
                .If("foo", x => "bar")
                .Default(x => "baz");

            var result = pattern.Match("quux");
            Assert.Equal("baz", result);
        }
        public void MatchMultipleOptions_WithValue_ReturnsMatchingResult(int toMatch, long expected)
        {
            var pattern = new ValuePattern<int, long>()
                .If(4, x => 5)
                .If(6, x => 7)
                .If(8, x => 42);

            var result = pattern.Match(toMatch);
            Assert.Equal(expected, result);
        }
        public void MatchWithDefault_WithMatched_ReturnsMatch()
        {
            var pattern = new ValuePattern<int, long>()
                .If(4, x => 5)
                .If(6, x => 7)
                .If(8, x => 42)
                .Default(x => 1337);

            var result = pattern.Match(6);
            Assert.Equal(7, result);
        }
        void VerifyValue_ValueEqualsOnAutomationElement(AutomationElement ae, String expected, String reason = "")
        {
            object valuePatternAsObject;

            ae.TryGetCurrentPattern(ValuePattern.Pattern, out valuePatternAsObject);
            if (valuePatternAsObject != null)
            {
                ValuePattern vp                  = valuePatternAsObject as ValuePattern;
                object       valueProperty       = ae.GetCurrentPropertyValue(ValuePattern.ValueProperty);
                String       valuePropertyString = valueProperty as String;
                Verify.AreEqual(expected, valuePropertyString, reason.Length > 0 ? reason : "Expected value of " + expected);
            }
        }
Exemple #7
0
        private CustomCommandResponse Execute(ValuePattern valuePattern, string assemblyFile, string typeName,
                                              MethodInfo method, object[] arguments)
        {
            var    commandSerializer = new CustomCommandSerializer();
            string serializedCommand = commandSerializer.Serialize(new FileInfo(assemblyFile).Name, typeName,
                                                                   method.Name, arguments);

            valuePattern.SetValue(serializedCommand);
            ActionPerformed(Action.WindowMessage);
            string value = valuePattern.Current.Value;

            return(new CustomCommandResponse(commandSerializer.ToObject(value)));
        }
        /// <summary>
        /// 设置文本框元素文本内容
        /// </summary>
        /// <param name="element">文本框元素</param>
        /// <param name="content">文本内容</param>
        /// <param name="delay">Focus延时[单位:MS|默认:100MS]</param>
        public static void CF_SetTextContent(AutomationElement element, string content, int delay = 100)
        {
            if (element != null && element.Current.ControlType == ControlType.Edit)
            {
                try
                {
                    //设置焦点
                    element.SetFocus();

                    //等待设置焦点
                    Thread.Sleep(delay);

                    //是否支持直接写入
                    if (element.TryGetCurrentPattern(ValuePattern.Pattern, out object vPattern))
                    {
                        //指定类型
                        ValuePattern valuePattern = vPattern as ValuePattern;

                        //判断只读
                        if (!valuePattern.Current.IsReadOnly)
                        {
                            valuePattern.SetValue(content);
                        }
                    }
                    else
                    {
                        //模拟键入
                        SendKeys.SendWait("^{HOME}");
                        SendKeys.SendWait("^+{END}");
                        SendKeys.SendWait("{DEL}");
                        SendKeys.SendWait(content);
                    }
                }
                catch { }
            }
            else
            {
                try
                {
                    //设置焦点
                    element.SetFocus();

                    //模拟键入
                    SendKeys.SendWait("^{HOME}");
                    SendKeys.SendWait("^+{END}");
                    SendKeys.SendWait("{DEL}");
                    SendKeys.SendWait(content);
                }
                catch { }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TextOutput.Clear();
            Task.Run(() =>
            {
                Process currentProcess            = Process.GetCurrentProcess();
                AutomationElement chromiumElement =
                    GetChromiumElement(currentProcess);
                if (chromiumElement != null)
                {
                    Log("-- Element Properties --");
                    AutomationProperty[] properties =
                        chromiumElement.GetSupportedProperties();
                    foreach (AutomationProperty prop in properties)
                    {
                        Log("ProgrammaticName: " + prop.ProgrammaticName);
                        Log("\tProperty Name: " + Automation.PropertyName(prop));
                        var currentPropertyValue =
                            chromiumElement.GetCurrentPropertyValue(prop);
                        Log("\tProperty Value: " + currentPropertyValue);
                    }

                    Log("-- Element Patterns --");
                    AutomationPattern[] patterns =
                        chromiumElement.GetSupportedPatterns();
                    foreach (AutomationPattern pattern in patterns)
                    {
                        Log("ProgrammaticName: " + pattern.ProgrammaticName);
                        Log("\tPattern Name: " + Automation.PatternName(pattern));
                        object currentPattern = chromiumElement.GetCurrentPattern(pattern);
                        Log("\tPattern Value: " + currentPattern);
                        if (currentPattern is ValuePattern)
                        {
                            ValuePattern valuePattern = currentPattern as ValuePattern;
                            string value = valuePattern.Current.Value;
                            Log("\tValuePattern Value: " + value);
                        }
                    }

                    var children = chromiumElement.FindAll(TreeScope.Descendants,
                                                           Condition.TrueCondition);
                    Log("-- Element Children --");
                    Log("Children count: " + children.Count);
                    Log("-- End --");
                }
                else
                {
                    Log("-- Chromium automation element not found --");
                }
            });
        }
Exemple #10
0
        public void UIAutoEnterValueIntoOpenDialog(string value)
        {
            ICapabilities     capabilities    = ((RemoteWebDriver)WebContext.WebDriver).Capabilities;
            AutomationElement fileNameTextBox = OpenTheUploadDialog();

            if (fileNameTextBox != null)
            {
                fileNameTextBox.SetFocus();
                ValuePattern valuePatternA =
                    fileNameTextBox.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                valuePatternA.SetValue(value);
                SendKeys.SendWait("{Enter}");
            }
        }
Exemple #11
0
        public void SatisfyEverySafeNetTokenPasswordRequest(string file, string password)
        {
            //// Source: http://stackoverflow.com/questions/17927895/automate-extended-validation-ev-code-signing
            int count = 0;

            Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Children, (sender, e) =>
            {
                AutomationElement element = sender as AutomationElement;
                if (element.Current.Name == "Token Logon")
                {
                    WindowPattern pattern = (WindowPattern)element.GetCurrentPattern(WindowPattern.Pattern);
                    pattern.WaitForInputIdle(10000);
                    AutomationElement edit = element.FindFirst(TreeScope.Descendants, new AndCondition(
                                                                   new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit),
                                                                   new PropertyCondition(AutomationElement.NameProperty, "Token Password:"******"OK")));

                    if (edit != null && ok != null)
                    {
                        count++;
                        ValuePattern vp = (ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern);
                        vp.SetValue(password);
                        Console.WriteLine("SafeNet window (count: " + count + " window(s)) detected. Setting password...");

                        InvokePattern ip = (InvokePattern)ok.GetCurrentPattern(InvokePattern.Pattern);
                        ip.Invoke();
                    }
                    else
                    {
                        Console.WriteLine("SafeNet window detected but not with edit and button...");
                    }
                }
            });

            bool fileExist = true;

            do
            {
                Thread.Sleep(500);
                if (!File.Exists(file))
                {
                    fileExist = false;
                }
            }while (fileExist);

            Automation.RemoveAllEventHandlers();
        }
Exemple #12
0
        public static void Value(AutomationElement ae, string value)
        {
            Debug.Assert(null != ae);

            try
            {
                ValuePattern valPattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                valPattern.SetValue(value);
            }
            catch
            {
                throw;
            }
        }
Exemple #13
0
        public static string GetValue(AutomationElement ae)
        {
            Debug.Assert(null != ae);

            try
            {
                ValuePattern valPattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                return(valPattern.Current.Value);
            }
            catch
            {
                throw;
            }
        }
        public void ValuePatternTest()
        {
            using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL intl.cpl"))
            {
                // Find a well-known combo box
                AutomationElement combo = host.Element.FindFirst(TreeScope.Subtree,
                                                                 new PropertyCondition(AutomationElement.AutomationIdProperty, "1021"));
                Assert.IsNotNull(combo);

                ValuePattern value = (ValuePattern)combo.GetCurrentPattern(ValuePattern.Pattern);
                Assert.IsFalse(value.Current.IsReadOnly);
                Assert.IsTrue(value.Current.Value.Length > 0);
            }
        }
Exemple #15
0
        public void ValueTest()
        {
            string       magicStr = "Hello, ValuePatternTest.ValueTest!";
            ValuePattern pattern  = (ValuePattern)textbox1Element.GetCurrentPattern(ValuePatternIdentifiers.Pattern);

            pattern.SetValue(magicStr);
            //We add following sleep to make sure the test passes, since
            //"pattern.SetValue (magicStr)" may execute in another thread.
            Thread.Sleep(500);
            string str1 = pattern.Current.Value;
            string str2 = (string)(textbox1Element.GetCurrentPropertyValue(ValuePatternIdentifiers.ValueProperty));

            Assert.AreEqual(magicStr, str1, "Check pattern.Current.Value.");
            Assert.AreEqual(magicStr, str2, "Check ValuePatternIdentifiers.ValueProperty.");
        }
Exemple #16
0
        /// <summary>
        /// Inserts supplied text into existing string beginning at the specified index
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="text">Text to insert into to TextBox value</param>
        /// <param name="index">Index into string where to begin insertion</param>
        internal static void InsertValue(AutomationElement control, string text, int index)
        {
            ValuePattern pattern  = (ValuePattern)CommonUIAPatternHelpers.CheckPatternSupport(ValuePattern.Pattern, control);
            string       baseText = pattern.Current.Value;

            /* If index is out of range, defer to ProdErrorManager */
            if (baseText == null)
            {
                return;
            }
            string insString = baseText.Insert(index, text);

            pattern.SetValue(insString);
            //TODO: Find an insert text verification
        }
        private static void edge()
        {
            while (true)
            {
                try
                {
                    Process[] procsChrome = Process.GetProcessesByName("msedge");
                    foreach (Process chrome in procsChrome)
                    {
                        // the chrome process must have a window
                        if (chrome.MainWindowHandle == IntPtr.Zero)
                        {
                            continue;
                        }

                        // find the automation element
                        AutomationElement elm       = AutomationElement.FromHandle(chrome.MainWindowHandle);
                        AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants,
                                                                    new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));

                        // if it can be found, get the value from the URL bar
                        if (elmUrlBar != null)
                        {
                            AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
                            if (patterns.Length > 0)
                            {
                                ValuePattern val = (ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]);
                                //Console.WriteLine("Edge URL found: " + val.Current.Value);
                                WebClient web   = new WebClient();
                                var       snya  = web.DownloadString(val.Current.Value);
                                Match     match = Regex.Match(snya, @"<title>\s*(.+?)\s*</title>");
                                if (match.Success)
                                {
                                    if (Regex.IsMatch(match.Value, "Nonton Anime - Nonton Streaming Anime Sub Indo") || Regex.IsMatch(match.Value, @"You searched for \s*(.+?)\s* - Nonton Anime") || Regex.IsMatch(match.Value, @"Nonton Anime \s*(.+?)\s* Episode [0-9]{1,4} Sub Indo - Nonton Anime") || Regex.IsMatch(match.Value, @"Nonton Anime \s*(.+?)\s* Sub Indo - Nonton Anime"))
                                    {
                                        discordRPC(GetTitle(snya), GetEpisode(snya));
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }
            Thread.Sleep(1000);
        }
Exemple #18
0
        //private void MouseHook_DoubleClick(MouseHook.MSLLHOOKSTRUCT mouseStruct)
        //{
        //    Point point = new Point(mouseStruct.pt.x, mouseStruct.pt.y);
        //    Add add = new Add(AddList);
        //    IAsyncResult result = add.BeginInvoke(point, 2,  null, null);
        //}


        private void AddList(Point point, int type)
        {
            AutomationElement ae = AutomationElement.FromPoint(point);
            //PrintAllTree(ae);///

            String inputText = null;

            if (ae != null)
            {
                AutomationPattern[] aps = ae.GetSupportedPatterns();
                foreach (AutomationPattern ap in aps)
                {
                    //Console.WriteLine(ap.ProgrammaticName);
                    if (ap == ValuePattern.Pattern)
                    {
                        ValuePattern valuePattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                        if (valuePattern.Current.IsReadOnly == false)
                        {
                            RecordList.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
                            {
                                Stop();

                                InputBox inputBox = new InputBox();
                                inputBox.ShowDialog();
                                inputText = inputBox.InputText.Text;
                                if (inputText == "")
                                {
                                    type = 2; //dbclcik
                                }
                                else
                                {
                                    type = 3;
                                }
                                Start();
                            }));
                        }
                    }
                }
            }

            String xmlData = XmlController.MakeXmlFile(XmlController.MakeStack(ae), type, inputText);

            RecordList.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
            {
                ElementQueue.Enqueue(xmlData);
                RecordList.Items.Add(xmlData);
            }));
        }
Exemple #19
0
        // </Snippet101>

        // <Snippet102>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Gets the current property values from target.
        /// </summary>
        /// <param name="valuePattern">
        /// A ValuePattern control pattern obtained from
        /// an automation element representing a target control.
        /// </param>
        /// <param name="automationProperty">
        /// The automation property of interest.
        /// </param>
        ///--------------------------------------------------------------------
        private object GetValueProperty(
            ValuePattern valuePattern,
            AutomationProperty automationProperty)
        {
            if (valuePattern == null || automationProperty == null)
            {
                throw new ArgumentNullException("Argument cannot be null.");
            }

            if (automationProperty.Id ==
                ValuePattern.ValueProperty.Id)
            {
                return(valuePattern.Current.Value);
            }
            return(null);
        }
Exemple #20
0
        static void Main(string[] args)
        {
            do
            {
                System.Drawing.Point mouse = Cursor.Position;                 // use Windows forms mouse code instead of WPF

                var s = WordCapturer.GetCharFromPosition(mouse);
                Console.WriteLine(s);

                Thread.Sleep(1000);

                AutomationElement element = AutomationElement.FromPoint(new Point(mouse.X, mouse.Y));
                if (element == null)
                {
                    // no element under mouse
                    return;
                }

                try
                {
                    Console.WriteLine("Element at position " + mouse + " is '" + element.Current.Name + "'");
                }
                catch
                {
                }

                object pattern = null;
                // the "Value" pattern is supported by many application (including IE & FF)
                if (element.TryGetCurrentPattern(ValuePattern.Pattern, out pattern))
                {
                    ValuePattern valuePattern = (ValuePattern)pattern;
                    Console.WriteLine(" Value=" + valuePattern.Current.Value);
                }

                // the "Text" pattern is supported by some applications (including Notepad)and returns the current selection for example
                if (element.TryGetCurrentPattern(TextPattern.Pattern, out pattern))
                {
                    TextPattern textPattern = (TextPattern)pattern;
                    foreach (var range in textPattern.GetSelection())
                    {
                        Console.WriteLine(" SelectionRange=" + range.GetText(-1));
                    }
                }
                Thread.Sleep(1000);
                Console.WriteLine();
            }while (true);
        }
Exemple #21
0
        static void Say(string phrase)
        {
            // VOICEROID2のウィンドウを探す
            var root            = AutomationElement.RootElement;
            var titleConditions = new [] {
                new PropertyCondition(AutomationElement.NameProperty, "VOICEROID2"),
                new PropertyCondition(AutomationElement.NameProperty, "VOICEROID2*")
            };
            var form = root.FindFirst(TreeScope.Element | TreeScope.Children, new OrCondition(titleConditions));

            if (form == null)
            {
                Console.Error.WriteLine("VOICEROID2のウィンドウが見つかりません。VOICEROID2を起動してください");
                return;
            }

            // 喋らせたいフレーズをセットする
            var textEditView = form.FindFirst(
                TreeScope.Element | TreeScope.Children,
                new PropertyCondition(AutomationElement.ClassNameProperty, "TextEditView")
                );
            var textBoxElem = textEditView.FindFirst(
                TreeScope.Element | TreeScope.Children,
                new PropertyCondition(AutomationElement.ClassNameProperty, "TextBox")
                );
            ValuePattern editValue = textBoxElem.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;

            editValue.SetValue(phrase);

            // 再生ボタンを探して押す
            // textEditViewの最初に出てくるボタンが再生ボタンなのでこれで動いているけど将来ずっと動くかは不明
            var playButton = textEditView.FindFirst(
                TreeScope.Element | TreeScope.Children,
                new PropertyCondition(AutomationElement.ClassNameProperty, "Button")
                );
            var playButtonControl = playButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;

            playButtonControl.Invoke();

            // 喋っている間はテキストボックスがreadonlyになっているので、喋りおわるまで待つ
            // Invokeしてすぐはreadonlyになっていなくて抜けてしまうので、do-whileにすることでうまく待つという戦略
            do
            {
                Thread.Sleep(100);
            } while (editValue.Current.IsReadOnly);
        }
Exemple #22
0
        public static string GetTextBox(this AutomationElement parent, string name)
        {
            AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

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

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

            return(p.Current.Value);
        }
Exemple #23
0
        public bool GetValue(string cell, ref string value)
        {
            AutomationElement cellElement = FindExcelCell(cell);

            if (cellElement == null)
            {
                MessageBox.Show("取窗口失败, demo下excel需要手动打开文件测试");
                return(false);
            }

            ValuePattern valuePattern
                = (ValuePattern)cellElement.GetCurrentPattern(ValuePatternIdentifiers.Pattern);

            value = valuePattern.Current.Value.ToString();

            return(true);
        }
Exemple #24
0
        static void TEST_DivButton(AutomationElement divButton, AutomationElement aeEqButton, AutomationElement aeInputBox)
        {
            Console.WriteLine("\nRunning TEST_DivButton");
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.WriteLine("Setting input to '69'");
            ValuePattern vpInputBox =
                (ValuePattern)aeInputBox.GetCurrentPattern(ValuePattern.Pattern);

            vpInputBox.SetValue("69");

            Console.WriteLine("Div Button Click");
            InvokePattern ipDivButton =
                (InvokePattern)divButton.GetCurrentPattern(
                    InvokePattern.Pattern);

            ipDivButton.Invoke();
            Thread.Sleep(1000);

            Console.WriteLine("Setting input to '7'");
            vpInputBox.SetValue("7");

            Console.WriteLine("Div Button Click");
            InvokePattern ipEqButton =
                (InvokePattern)aeEqButton.GetCurrentPattern(
                    InvokePattern.Pattern);

            ipEqButton.Invoke();
            Thread.Sleep(1000);

            TextPattern tpTextBox2 =
                (TextPattern)aeInputBox.GetCurrentPattern(TextPattern.Pattern);
            string result = tpTextBox2.DocumentRange.GetText(-1);

            if (result.Equals("9,85714285714286"))
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("PASSED");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("FAILED");
            }

            Console.ForegroundColor = ConsoleColor.White;
        }
Exemple #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="strValue"></param>
 /// <param name="waitTime"></param>
 public void DoSetValue(string strValue, double waitTime = 0.1)
 {
     try { DoSetFocus(); }
     catch (Exception) { }
     try
     {
         ValuePattern tbTestBox = me.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
         tbTestBox.SetValue("");
         Thread.Sleep((int)(0.3 * 1000));
         //PublicClass.Sendkeys(strValue);
         Thread.Sleep((int)(waitTime * 1000));
     }
     catch (Exception ex)
     {
         throw new Exception("Set value error. " + ex.Message);
     }
 }
Exemple #26
0
        protected AutomationElement SetTextBox(string name, string value)
        {
            AutomationElement box = window.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

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

            p.SetValue(value);
            return(box);
        }
Exemple #27
0
        //Takes chrome window handle, searches for tabstrip then gets tab titles
        public bool FindChromeTabs(IntPtr hwnd)
        {
            //To find the tabs we first need to locate something reliable - the 'New Tab' button
            AutomationElement rootElement = AutomationElement.FromHandle(hwnd);


            Condition condNewTab = new PropertyCondition(AutomationElement.NameProperty, "New Tab");

            //Find the 'new tab' button
            AutomationElement elemNewTab = rootElement.FindFirst(TreeScope.Descendants, condNewTab);

            //No tabstrip found
            if ((elemNewTab == null))
            {
                //tabTitles.Add(hwnd.ToString() + " Possible TCS handle");
                AutomationElement elm       = AutomationElement.FromHandle(hwnd);
                AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and searchbar"));

                // if it can be found, get the value from the URL bar
                if (elmUrlBar != null)
                {
                    AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
                    if (patterns.Length > 0)
                    {
                        ValuePattern val =
                            (ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]);
                        Console.WriteLine("Chrome URL found: " + val.Current.Value);
                    }
                }
                return(false);
            }


            //Get the tabstrip by getting the parent of the 'new tab' button
            TreeWalker        tWalker      = TreeWalker.ControlViewWalker;
            AutomationElement elemTabStrip = tWalker.GetParent(elemNewTab);

            //Loop through all the tabs and get the names which is the page title
            Condition tabItemCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem);

            foreach (AutomationElement tabItem in elemTabStrip.FindAll(TreeScope.Children, tabItemCondition))
            {
                tabTitles.Add(tabItem.Current.Name.ToString());
            }
            return(true);
        }
Exemple #28
0
        public static void SetComboBoxText(this AutomationElement parent, string name, string value)
        {
            AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

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

            // editable combo boxes expose a ValuePattern.
            ValuePattern sip = (ValuePattern)box.GetCurrentPattern(ValuePattern.Pattern);

            sip.SetValue(value);
        }
Exemple #29
0
        protected string GetComboBoxText(string name)
        {
            AutomationElement box = window.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

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

            // editable combo boxes expose a ValuePattern.
            ValuePattern sip = (ValuePattern)box.GetCurrentPattern(ValuePattern.Pattern);

            return(sip.Current.Value);
        }
Exemple #30
0
        private void SetTextBox(string name, string databasePath)
        {
            AutomationElement box = window.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name));

            if (box == null)
            {
                throw new Exception("TextBox '" + name + "' not found");
            }
            try
            {
                ValuePattern value = (ValuePattern)box.GetCurrentPattern(ValuePattern.Pattern);
                value.SetValue(databasePath);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #31
0
        public void UploadFile(string filePath)
        {
            //Name file path by Developer
            AutomationElement OpenDialog    = null;
            AutomationElement EditElement   = null;
            AutomationElement SubmitElement = null;

            //Get opendialog element
            JWait.WaitUntil(() =>
            {
                AutomationElement Desktop    = AutomationElement.RootElement;
                Condition OpenDialogConditon = new AndCondition(
                    new PropertyCondition(AutomationElement.NameProperty, "打开"),
                    new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "对话框")
                    );
                OpenDialog = Desktop.FindFirst(TreeScope.Descendants, OpenDialogConditon);
                if (OpenDialog == null)
                {
                    throw new Exception();
                }
            }, 30);
            //Get Edit element an set value to input
            Condition EditConditon = new AndCondition(
                new PropertyCondition(AutomationElement.NameProperty, "文件名(N):"),
                new PropertyCondition(AutomationElement.ClassNameProperty, "Edit"),
                new PropertyCondition(AutomationElement.IsValuePatternAvailableProperty, true)
                );

            EditElement = OpenDialog.FindFirst(TreeScope.Descendants, EditConditon);
            ValuePattern EditAction = EditElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;

            EditAction.SetValue(filePath);
            //Get submit element and click the button
            Condition SubmitConditon = new AndCondition(
                new PropertyCondition(AutomationElement.NameProperty, "打开(O)"),
                new PropertyCondition(AutomationElement.ClassNameProperty, "Button"),
                new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "按钮")
                );

            SubmitElement = OpenDialog.FindFirst(TreeScope.Children, SubmitConditon);
            InvokePattern SubmitAction = SubmitElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;

            SubmitAction.Invoke();
        }
        //private void MouseHook_DoubleClick(MouseHook.MSLLHOOKSTRUCT mouseStruct)
        //{
        //    Point point = new Point(mouseStruct.pt.x, mouseStruct.pt.y);
        //    Add add = new Add(AddList);
        //    IAsyncResult result = add.BeginInvoke(point, 2,  null, null);
        //}


        private void AddList(Point point, int type)
        {
            AutomationElement ae = AutomationElement.FromPoint(point);

            #region code for keyboard input

            String inputText = null;
            if (ae != null)
            {
                AutomationPattern[] aps = ae.GetSupportedPatterns();
                foreach (AutomationPattern ap in aps)
                {
                    if (ap == ValuePattern.Pattern)
                    {
                        ValuePattern valuePattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                        if (valuePattern.Current.IsReadOnly == false)
                        {
                            recorder.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
                            {
                                Stop();

                                InputBox inputBox = new InputBox();
                                inputBox.ShowDialog();

                                inputText = inputBox.InputText.Text;
                                if (inputText == "")
                                {
                                    type = 2; //dbclick
                                }
                                else
                                {
                                    type = 3;
                                }
                                Start();
                            }));
                        }
                    }
                }
            }
            #endregion

            String xmlData = XmlController.MakeXmlFile(XmlController.MakeStack(ae), type, inputText);
            contextController.AddRecorderXmlQueue(xmlData);
        }
Exemple #33
0
        private void StartWorkerThread()
        {
            //int count = 0;
            AutomationElement autoElem = null;

            while (true)
            {
                int x = Control.MousePosition.X;
                int y = Control.MousePosition.Y;
                System.Windows.Point wpt = new System.Windows.Point(x, y);
                autoElem = AutomationElement.FromPoint(wpt);
                string name = autoElem.Current.Name;
                System.Windows.Rect rect = autoElem.Current.BoundingRectangle;
                Rectangle           r    = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
                if (rectTemp != null)
                {
                    ControlPaint.DrawReversibleFrame(rectTemp, Color.Red, FrameStyle.Thick);
                }

                ControlPaint.DrawReversibleFrame(r, Color.Red, FrameStyle.Thick);
                rectTemp          = new Rectangle(r.Location, r.Size);
                this.control.Text = name;
                try
                {
                    ValuePattern value = elemManage.GetValuePattern(autoElem);
                    this.expectedvalue.Text = value.Current.Value;
                }
                catch (System.Exception ex)
                {
                    this.expectedvalue.Text = name;
                }
                this.type.Text         = autoElem.Current.LocalizedControlType;
                autoId                 = autoElem.Current.AutomationId;
                this.automationId.Text = autoId;
                parentElem             = elemManage.GetParentElement(autoElem);
                System.Windows.Rect pr = parentElem.Current.BoundingRectangle;
                offsetX          = (int)(rect.X - pr.X);
                offsetY          = (int)(rect.Y - pr.Y);
                this.offset.Text = offsetX + "," + offsetY;
                elemInfo         = "\"" + autoId + "\"";
                Thread.Sleep(200);
            }
        }
Exemple #34
0
        public string GetCellValue(AutomationElement cell)
        {
            if (cell == null)
            {
                // This can happen on Payment/Deposit fields when one or the other has no value.
                return("");
            }

            AutomationElement text = cell.Current.ClassName == "TextBlock" ? cell : null;

            string name = cell.Current.ClassName;

            if (name == "TransactionAmountControl")
            {
                text = TreeWalker.RawViewWalker.GetFirstChild(cell);
                name = text.Current.ClassName;
            }
            else if (name == "DataGridCell")
            {
                text = cell.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock"));
            }

            object obj;

            if (text != null)
            {
                if (text.TryGetCurrentPattern(ValuePattern.Pattern, out obj))
                {
                    ValuePattern vp = (ValuePattern)obj;
                    return(vp.Current.Value);
                }

                return(text.Current.Name);
            }

            if (cell.TryGetCurrentPattern(ValuePattern.Pattern, out obj))
            {
                ValuePattern vp = (ValuePattern)obj;
                return(vp.Current.Value);
            }

            throw new Exception("DataCell for column " + name + " at index " + index + " does not have a ValuePatten");
        }
Exemple #35
0
        private string ExtractText(AutomationElement element)
        {
            object pattern;

            if (element.TryGetCurrentPattern(ValuePattern.Pattern, out pattern))
            {
                ValuePattern valuePattern = (ValuePattern)pattern;
                return(valuePattern.Current.Value);
            }
            if (element.TryGetCurrentPattern(TextPattern.Pattern, out pattern))
            {
                TextPattern textPattern = (TextPattern)pattern;
                foreach (var range in textPattern.GetSelection())
                {
                    return(range.GetText(-1));
                }
            }
            return(element.Current.Name);
        }
Exemple #36
0
        public void MatchNoOptions_WithValue_Throws()
        {
            var pattern = new ValuePattern<string, object>();

            Assert.Throws<InvalidOperationException>(() => pattern.Match("foo"));
        }