实施UITestPropertyProvider后,AccessibleName仍然不是有效的Searchproperty

保罗

我需要使用Visual Studio编码的UI测试为Delphi应用程序实现自动UI测试。我已经在Delphi-Contols中实现了IAccessible接口。它工作正常,我从控件中获取了AccessibleName。

然后,我为Visual Studio实施了扩展。在这个扩展中,我有自己的PropertyProvider,ExtensionPackage和WinControl-Class。

PropertyProvider:

namespace CUITExtension
{
    public class AccessibleNamePropertyProvider : UITestPropertyProvider
    {    
        private static Dictionary<string, UITestPropertyDescriptor> accessibleNamePropertyMap = null;
        private static Dictionary<string, UITestPropertyDescriptor> AccessibleNamePropertyMap
        {
            get
            {
                if (accessibleNamePropertyMap == null)
                {
                    UITestPropertyAttributes read = UITestPropertyAttributes.Readable
                        | UITestPropertyAttributes.DoNotGenerateProperties;
                    accessibleNamePropertyMap = new Dictionary<string, UITestPropertyDescriptor>
                            (StringComparer.OrdinalIgnoreCase);
                    accessibleNamePropertyMap.Add("AccessibleName", new UITestPropertyDescriptor(typeof(string), read));
                }
                return accessibleNamePropertyMap;
            }
        }

        public override UITestPropertyDescriptor GetPropertyDescriptor(UITestControl uiTestControl, string propertyName)
        {
            return AccessibleNamePropertyMap[propertyName];
        }

        public override ICollection<string> GetPropertyNames(UITestControl uiTestControl)
        {
            if (uiTestControl.ControlType.NameEquals("Custom"))
            {
                // the keys of the property map are the collection of property names
                return AccessibleNamePropertyMap.Keys;
            }
            throw new NotSupportedException();
        }

        public override object GetPropertyValue(UITestControl uiTestControl, string propertyName)
        {
            if (String.Equals(propertyName, "AccessibleName", StringComparison.OrdinalIgnoreCase))
            {
                object[] native = uiTestControl.NativeElement as object[];
                IAccessible acc = native[0] as IAccessible;

                return acc.accName;
            }
            throw new NotSupportedException();
        }

        public override int GetControlSupportLevel(UITestControl uiTestControl)
        {
            if (string.Equals(uiTestControl.TechnologyName, "MSAA",
                StringComparison.OrdinalIgnoreCase) &&
                uiTestControl.ControlType.NameEquals("Custom"))
            {
                return (int)ControlSupport.ControlSpecificSupport;
            }

            // This is not my control, so return NoSupport
            return (int)ControlSupport.NoSupport;
        }

        public override string[] GetPredefinedSearchProperties(Type specializedClass)
        {
            return null;
        }

        public override string GetPropertyForAction(UITestControl uiTestControl, UITestAction action)
        {
            return null;
        }

        public override string[] GetPropertyForControlState(UITestControl uiTestControl, ControlStates uiState, out bool[] stateValues)
        {
            stateValues = null;
            return null;
        }

        public override Type GetPropertyNamesClassType(UITestControl uiTestControl)
        {
            if (uiTestControl.ControlType.NameEquals("Custom"))
                return typeof(AccessibleControl.PropertyNames);

            return null;
        }

        public override Type GetSpecializedClass(UITestControl uiTestControl)
        {
            if (uiTestControl.ControlType.NameEquals("Custom"))
                return typeof(AccessibleControl);

            return null;
        }

        public override void SetPropertyValue(UITestControl uiTestControl, string propertyName, object value)
        {
            return;
        }
    }
}

扩展包:

[assembly: Microsoft.VisualStudio.TestTools.UITest.Extension.UITestExtensionPackage(
                "AccessibleNameExtensionPackage",
                typeof(CUITExtension.AccessibleNameExtensionPackage))]
namespace CUITExtension
{

    class AccessibleNameExtensionPackage : UITestExtensionPackage
    {
        public override string PackageDescription
        {
            get { return "Supports coded UI testing by using the AccessibleName"; }
        }

        public override string PackageName
        {
            get { return "AccessibleName Extension Package"; }
        }

        public override string PackageVendor
        {
            get { return "Microsoft (sample)"; }
        }

        public override Version PackageVersion
        {
            get { return new Version(1, 0); }
        }

        public override Version VSVersion
        {
            get { return new Version(14, 0); }
        }

        public override void Dispose() { }

        public override object GetService(Type serviceType)
        {
            if (serviceType == typeof(UITestPropertyProvider))
            {
                if (propertyProvider == null)
                {
                    propertyProvider = new AccessibleNamePropertyProvider();
                }
                return propertyProvider;
            }
            return null;
        }

        private UITestPropertyProvider propertyProvider = null;
    }
}

WinControl:

namespace CUITExtension
{
    public class AccessibleControl : WinControl
    {
        public AccessibleControl(UITestControl c) : base(c)
        {
            TechnologyName = "MSAA";
            SearchProperties.Add(UITestControl.PropertyNames.ControlType, "Custom");
        }

        public virtual string AccessibleName
        {
            get
            {
                return (string)GetProperty("AccessibleName");
            }
        }
    }
}

现在,编码的UI测试生成器将显示AccessibleName,并且还将生成AccessibleName作为SearchProperty。

UIMap:

public AccessibleControl UIItemCustom
        {
            get
            {
                if ((this.mUIItemCustom == null))
                {
                    this.mUIItemCustom = new AccessibleControl(this);
                    #region Search Criteria
                    this.mUIItemCustom.SearchProperties["AccessibleName"] = "UniqueName1";
                    this.mUIItemCustom.SearchProperties[WinControl.PropertyNames.ClassName] = "TEdit";
                    this.mUIItemCustom.WindowTitles.Add("Title");
                    #endregion
                }
                return this.mUIItemCustom;
            }
        }

*我在这里更改了Searchproperties(仅针对帖子,我没有更改生成的代码)

现在,当我开始测试时,出现一个异常,指出AccessibleName不是有效的搜索属性。当我还没有实现扩展时,我就收到了这个异常。但是我认为通过实现属性提供程序AccessibleName现在应该是一个有效的搜索属性。我试图调试它,但是似乎通过搜索控件它没有使用propertyprovider,我也不知道为什么吗?

希望您能为我提供帮助,如果您需要更多信息,请询问。

保罗

保罗

我遇到了有效的搜索属性正常工作的问题。我从WinControl覆盖了GetValidSearchProperties方法。

protected override Dictionary<string, bool> GetValidSearchProperties()
        {
            Dictionary<string, bool> searchProperties = base.GetValidSearchProperties();
            if (!searchProperties.ContainsKey("AccessibleName"))
                searchProperties.Add("AccessibleName", true);
            return searchProperties;
        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

“数字”不是声明的变量,但仍然有效吗?

PHP中的if条件后的分号-代码仍然有效

删除类后,jQuery函数仍然有效

调用 removeEventListener 后滚动事件仍然有效

Cookie在删除Ajax请求后仍然有效

参数更改后订阅仍然有效

有效的C ++仍然有效吗?

实施命令模式有效

有效实施CRC16

Faulhaber公式的有效实施

如何使条带支付实施有效?

为什么DNS仍然有效?

停用Chrome网页安全性后,CORS是否仍然有效?

超出范围后,指向__FILE__的指针是否仍然有效?

离开范围后,为什么仍然可以有效访问struct?

即使开始输出后,php位置标头重定向仍然有效

SignalR 连接已关闭,但在 angularjs 范围破坏后仍然有效

Gmail Api访问令牌在到期后不会更改-但访问仍然有效

SQLite DB在准备后关闭,但stmt仍然有效吗?

连接到VPN后,本地SSH连接仍然有效

在Java中循环结束后对字符串的更改仍然有效

即使在子功能退出后,在子功能内创建的节点仍然有效吗?

为什么重新启动结构网络后以前的 ecert 和密钥仍然有效?

获得 FCM 令牌后 APNS 令牌是否仍然有效

“ <...>不是有效的NSFetchRequest。”

我的 views.py 文件中有一个有效的视图,但仍然给我错误“不是有效的视图函数”

有没有更有效的实施?

当我输入A,B,C或D时,仍然显示那不是有效答案。为什么?

为什么将数组显示为1D而不是2D,但该表仍然有效?