UI Automation-ValuePattern

来源:互联网 发布:mac spss许可证 编辑:程序博客网 时间:2024/05/18 00:29

 感谢原作者的分享  http://blog.csdn.net/lynn_yan/article/category/611860


ValuePattern是UI Automationz中最常见的Pattern之一,winform和WPF的TextBox控件都支持ValuePattern,是用来get/set a value on a control that doesnot support multiple values.

实现valuePattern用我正在测试的软件,发现输入Email address,总是提示输入的Email Address不正确,最后才发现时因为ValuePattern中的setvalue是对整个textbox赋值,而我们的软件根本没有ignore space,所以总会跳出一个warning message。

       public static ValuePattern GetValuePattern(AutomationElement element)

        {

            object currentPattern = null;

            if (!element.TryGetCurrentPattern(ValuePattern.Pattern, out currentPattern))

            {

                Log.Error(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the ValuePattern.",

    element.Current.AutomationId, element.Current.Name));

                throw new Exception(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the ValuePattern.",

                    element.Current.AutomationId, element.Current.Name));

            }

            return currentPattern as ValuePattern;

        }

Test Value Pattern

//Get the button element

            AutomationElement textbox = AutomationElementSearch.FindElementById(window, "textBox1");

            Assert.IsNotNull(textbox);

            Thread.Sleep(1000);

 

            ValuePattern textboxpattern = Valuepattern.GetValuePattern(textbox);

            textboxpattern.SetValue("ValuePattern Test");


0 0
原创粉丝点击