Exemplo n.º 1
0
        public static UIObject GetTopLevelUIObject(UIObject topWindow)
        {
            if (topWindow == null)
            {
                throw new ArgumentNullException(paramName: nameof(topWindow));
            }
            Log.Out(msg: "GetTopLevelUIObject: object");
            UIObject element = null;

            if ((ControlType)topWindow.GetProperty(property: UIProperty.Get(name: "ControlType")) != ControlType.Window)
            {
                throw new InvalidOperationException(message: "topWindow didn't find a window (ControlType==Window) after app activation completed.");
            }
            if (topWindow.ClassName.Equals(value: "Windows.UI.Core.CoreWindow", comparisonType: StringComparison.OrdinalIgnoreCase))
            {
                element = topWindow;
            }
            else
            {
                uint num;
                for (num = 0U; num < 10U && !topWindow.Children.TryFind(condition: UICondition.CreateFromClassName(className: "Windows.UI.Core.CoreWindow").AndWith(newCondition: UICondition.CreateFromName(name: topWindow.Name)), element: out element); ++num)
                {
                    Thread.Sleep(millisecondsTimeout: 100);
                }
                if (element == null)
                {
                    throw new UIObjectNotFoundException(message: string.Format(format: "Unable to find {0} in {1}", arg0: "Windows.UI.Core.CoreWindow", arg1: topWindow));
                }
                Log.Out(msg: "Found {0} in {1} tries", (object)"Windows.UI.Core.CoreWindow", (object)num);
            }

            return(element);
        }
Exemplo n.º 2
0
        public UICollection <I> FindMultiple(UICondition condition)
        {
            var uiCollection = Duplicate();

            uiCollection.AddFilter(condition: condition);
            return(uiCollection);
        }
Exemplo n.º 3
0
        public I Find(UICondition condition)
        {
            I element;

            if (!TryFind(condition: condition, element: out element))
            {
                throw new UIObjectNotFoundException(searchDomain: ToString(), condition: condition);
            }
            return(element);
        }
Exemplo n.º 4
0
        public static UIObject Launch(string appName, UICondition topLevelWindowCondition)
        {
            Log.Out(msg: nameof(Launch));
            UIObject source;

            using (var appLaunchWaiter = new AppLaunchWaiter(topLevelWindowCondition: topLevelWindowCondition)) {
                new ApplicationActivationManager().ActivateApplication(appUserModelId: appName, arguments: null, options: ActivateOptions.None, processId: out var _);
                appLaunchWaiter.Wait();
                source = appLaunchWaiter.Source;
            }

            return(GetTopLevelUIObject(topWindow: source));
        }
Exemplo n.º 5
0
        public static UIObject LaunchEx(string appName, UICondition topLevelWindowCondition)
        {
            Log.Out(msg: "Launch");
            UIObject source;

            using (var appLaunchWaiter = new AppLaunchWaiter(topLevelWindowCondition: topLevelWindowCondition)) {
                AppStateManagementUtils.LaunchApplication(AumId: appName);
                appLaunchWaiter.Wait();
                source = appLaunchWaiter.Source;
            }

            return(GetTopLevelUIObject(topWindow: source));
        }
Exemplo n.º 6
0
        public static UIObject GetTopLevelUIObject(UICondition topLevelWindowCondition)
        {
            if (topLevelWindowCondition == null)
            {
                throw new ArgumentNullException(paramName: nameof(topLevelWindowCondition));
            }
            Log.Out(msg: "GetTopLevelUIObject: condition");
            UIObject element;

            if (!UIObject.Root.Descendants.TryFind(condition: topLevelWindowCondition, element: out element))
            {
                throw new InvalidOperationException(message: "topLevelWindowCondition didn't find an element after app activation completed.");
            }
            return(GetTopLevelUIObject(topWindow: element));
        }
        public override Condition GlobalizeCondition(
            AutomationElement element,
            ref Dictionary <AutomationProperty, TranslatedStrings> propertyValueTranslations)
        {
            Condition condition = this._condition;

            if (UICondition.IsGlobalizableProperty(property: this._property))
            {
                TranslatedStrings translatedStrings;
                if (!propertyValueTranslations.TryGetValue(key: this._property, value: out translatedStrings))
                {
                    translatedStrings = new TranslatedStrings();
                    propertyValueTranslations[key : this._property] = translatedStrings;
                }

                var localizedStrings = !(this._value is ILocalizationProvider2) ? new LocalizedStringsAdapter(taggedText: this._value.ToString()) : (ILocalizedStrings) new LocalizedStrings2(contextElement: element, provider: (ILocalizationProvider2)this._value);
                var translations     = localizedStrings.GetTranslations();
                if (1 == translations.Length)
                {
                    translatedStrings.Add(translatedString: translations[0].Raw(), localizedStrings: localizedStrings, index: 0L);
                    condition = new PropertyCondition(property: this._property, value: translations[0].DefaultString());
                }
                else
                {
                    var conditionArray = new Condition[translations.Length];
                    for (var index = 0; index < translations.Length; ++index)
                    {
                        translatedStrings.Add(translatedString: translations[index].Raw(), localizedStrings: localizedStrings, index: index);
                        conditionArray[index] = new PropertyCondition(property: this._property, value: translations[index].DefaultString());
                    }

                    condition = new OrCondition(conditions: conditionArray);
                }
            }

            return(condition);
        }
Exemplo n.º 8
0
        public static UIObject LaunchForProtocol(
            string appName,
            string uri,
            UICondition topLevelWindowCondition)
        {
            Log.Out(msg: nameof(LaunchForProtocol));
            var        riid1 = new Guid(g: "43826d1e-e718-42ee-bc55-a1e261c37bfe");
            IShellItem shellItem;

            SHCreateItemFromParsingName(path: uri, pbc: IntPtr.Zero, riid: ref riid1, shellItem: out shellItem);
            var             riid2 = new Guid(g: "b63ea76d-1f85-456f-a19c-48159efa858b");
            IShellItemArray ppenum;

            STORAGE_SHCreateShellItemArrayFromShellItem(psi: shellItem, riid: ref riid2, ppenum: out ppenum);
            UIObject source;

            using (var appLaunchWaiter = new AppLaunchWaiter(topLevelWindowCondition: topLevelWindowCondition)) {
                new ApplicationActivationManager().ActivateForProtocol(appUserModelId: appName, itemArray: ppenum, processId: out var _);
                appLaunchWaiter.Wait();
                source = appLaunchWaiter.Source;
            }

            return(GetTopLevelUIObject(topWindow: source));
        }
Exemplo n.º 9
0
 public void AddFilter(UIProperty uiProperty, object value)
 {
     Navigator.AddFilter(condition: UICondition.Create(property: uiProperty, value: value));
 }
Exemplo n.º 10
0
 public void AddFilter(UICondition condition)
 {
     Navigator.AddFilter(condition: condition);
 }
Exemplo n.º 11
0
        public static UICondition CreateTopLevelWindowCondition()
        {
            var deviceFamily = AnalyticsInfo.VersionInfo.DeviceFamily;

            return(deviceFamily.Equals(value: "Windows.Desktop", comparisonType: StringComparison.OrdinalIgnoreCase) || deviceFamily.Equals(value: "Windows.Server", comparisonType: StringComparison.OrdinalIgnoreCase) || deviceFamily.Equals(value: "Windows.Team", comparisonType: StringComparison.OrdinalIgnoreCase) ? UICondition.CreateFromClassName(className: "ApplicationFrameWindow") : UICondition.CreateFromClassName(className: "Windows.UI.Core.CoreWindow"));
        }
Exemplo n.º 12
0
 public bool Contains(string automationId)
 {
     return(Contains(condition: UICondition.CreateFromId(automationId: automationId)));
 }
Exemplo n.º 13
0
 public UICondition AndWith(UICondition newCondition)
 {
     Validate.ArgumentNotNull(parameter: newCondition, parameterName: nameof(newCondition));
     Validate.ArgumentNotNull(parameter: newCondition.GlobalizableCondition, parameterName: "newCondition.GlobalizableCondition");
     return(new UICondition(condition: new GlobalizableAndCondition(GlobalizableCondition, newCondition.GlobalizableCondition)));
 }
Exemplo n.º 14
0
 internal static bool Matches(AutomationElement element, UICondition condition)
 {
     Validate.ArgumentNotNull(parameter: condition, parameterName: nameof(condition));
     return(condition.Matches(element: element));
 }
Exemplo n.º 15
0
 public bool TryFind(string automationId, out I element)
 {
     return(TryFind(condition: UICondition.CreateFromId(automationId: automationId), element: out element));
 }
Exemplo n.º 16
0
 public bool Contains(UIProperty uiProperty, object value)
 {
     return(Contains(condition: UICondition.Create(property: uiProperty, value: value)));
 }
Exemplo n.º 17
0
 public Context(UICondition treeCondition)
 {
     Validate.ArgumentNotNull(parameter: treeCondition, parameterName: nameof(treeCondition));
     IsActivated   = false;
     TreeCondition = treeCondition;
 }
Exemplo n.º 18
0
 public I Find(UIProperty uiProperty, object value)
 {
     return(Find(condition: UICondition.Create(property: uiProperty, value: value)));
 }
Exemplo n.º 19
0
 public I Find(string automationId)
 {
     return(Find(condition: UICondition.CreateFromId(automationId: automationId)));
 }
Exemplo n.º 20
0
 public bool TryFind(UICondition condition, out I element)
 {
     element = SafeFind(condition: condition);
     return(!(null == element));
 }
Exemplo n.º 21
0
 public bool TryFind(UIProperty uiProperty, object value, out I element)
 {
     return(TryFind(condition: UICondition.Create(property: uiProperty, value: value), element: out element));
 }
Exemplo n.º 22
0
 public static bool Matches(UIObject uiObject, UICondition condition)
 {
     Validate.ArgumentNotNull(parameter: uiObject, parameterName: nameof(uiObject));
     Validate.ArgumentNotNull(parameter: condition, parameterName: nameof(condition));
     return(condition.Matches(element: uiObject.AutomationElement));
 }
Exemplo n.º 23
0
 public UICollection <I> FindMultiple(UIProperty uiProperty, object value)
 {
     return(FindMultiple(condition: UICondition.Create(property: uiProperty, value: value)));
 }
Exemplo n.º 24
0
 public bool Contains(UICondition condition)
 {
     return(!(null == SafeFind(condition: condition)));
 }
 public UIObjectNotFoundException(string searchDomain, UICondition condition)
 {
     Validate.ArgumentNotNull(parameter: condition, parameterName: nameof(condition));
     Initialize(searchDomain: searchDomain, searchCriteria: condition.ToString());
 }
Exemplo n.º 26
0
 public void AddFilter(UICondition condition)
 {
     Filter.Add(condition: condition);
 }