示例#1
0
        /// <summary>
        /// Creates an instance of <see cref="Element"/> for UI item.
        /// </summary>
        /// <typeparam name="T">A desired type or subtype of instance to initialize.</typeparam>
        /// <param name="itemWrapper">An automation framework-specific wrapper of UI item.</param>
        /// <param name="uiNavigationProvider">
        /// Service for locating UI items and navigating
        /// among several running applications.
        /// </param>
        /// <param name="elementFactory">
        /// Service for locating UI items in a visual tree
        /// and initializing instances of <see cref="Element"/> for located items.
        /// </param>
        /// <param name="awaitingService">Service for awaiting various conditions to match.</param>
        /// <param name="logger">Logging service.</param>
        /// <returns>Created instance.</returns>
        public T CreateElement <T>(
            IUiItemWrapper itemWrapper,
            IUiNavigationProvider uiNavigationProvider,
            IElementFactory elementFactory,
            IAwaitingService awaitingService,
            ILogger logger)
            where T : Element
        {
            foreach (var factory in this.elementFactories)
            {
                T result = factory.CreateElement <T>(
                    itemWrapper,
                    uiNavigationProvider,
                    elementFactory,
                    awaitingService,
                    logger);

                if (result != default(T))
                {
                    return(result);
                }
            }

            throw new ArgumentException($"ElementCreator Couldn't create element of type {typeof(T).FullName}");
        }
示例#2
0
        public T CreateElement <T>(
            IUiItemWrapper itemWrapper,
            IUiNavigationProvider uiNavigationProvider,
            IElementFactory elementFactory,
            IAwaitingService awaitingService,
            ILogger logger)
            where T : Element
        {
            var type = typeof(T);

            if (type == typeof(NumericParameterElement))
            {
                return(new NumericParameterElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(StringParameterElement))
            {
                return(new StringParameterElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(EnumerationParameterElement))
            {
                return(new EnumerationParameterElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(BitEnumerationParameterElement))
            {
                return(new BitEnumerationParameterElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(DateTimeParameterElement))
            {
                return(new DateTimeParameterElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }

            return(default);
 public AppiumUiItemWrapper CreateDesktopWrapper(
     WindowsElement element,
     WindowsDriver <WindowsElement> driver,
     ILogger logger,
     ISettings settings,
     IAwaitingService awaitingService)
 {
     return(this.CreateWrapper(element, DesktopClassName, driver, logger, settings, awaitingService, null));
 }
示例#4
0
 internal DataGridCellElement(
     IUiItemWrapper itemWrapper,
     IUiNavigationProvider uiNavigationProvider,
     IElementFactory elementFactory,
     IAwaitingService awaitingService,
     ILogger logger)
     : base(
         itemWrapper,
         uiNavigationProvider,
         elementFactory,
         awaitingService,
         logger)
 {
 }
示例#5
0
 protected internal TreeViewElement(
     IUiItemWrapper itemWrapper,
     IUiNavigationProvider uiNavigationProvider,
     IElementFactory elementFactory,
     IAwaitingService awaitingService,
     ILogger logger)
     : base(
         itemWrapper,
         uiNavigationProvider,
         elementFactory,
         awaitingService,
         logger)
 {
 }
示例#6
0
 protected internal CheckBoxElement(
     IUiItemWrapper itemWrapper,
     IUiNavigationProvider uiNavigationProvider,
     IElementFactory elementFactory,
     IAwaitingService awaitingService,
     ILogger logger)
     : base(
         itemWrapper,
         uiNavigationProvider,
         elementFactory,
         awaitingService,
         logger)
 {
     this.logger = logger;
 }
示例#7
0
文件: Element.cs 项目: dmitry-abt/atf
        /// <summary>
        /// Initializes a new instance of the <see cref="Element"/> class.
        /// </summary>
        /// <param name="itemWrapper">Wrapped UI item by specific UI automation framework.</param>
        /// <param name="uiNavigationProvider">
        /// A service for locating UI items and navigating
        /// among several running applications.
        /// </param>
        /// <param name="elementFactory">
        /// A service for helping locating UI items in a visual tree
        /// and initializing instances of <see cref="Element"/> for located items.
        /// </param>
        /// <param name="awaitingService">A service for awaiting various conditions to match.</param>
        /// <param name="logger">A loggind service.</param>
        protected internal Element(
            IUiItemWrapper itemWrapper,
            IUiNavigationProvider uiNavigationProvider,
            IElementFactory elementFactory,
            IAwaitingService awaitingService,
            ILogger logger)
        {
            this.Instance = itemWrapper ?? throw new ArgumentNullException(nameof(itemWrapper));

            this.uiNavigationProvider = uiNavigationProvider ?? throw new ArgumentNullException(nameof(uiNavigationProvider));
            this.elementFactory       = elementFactory ?? throw new ArgumentNullException(nameof(elementFactory));
            this.awaitingService      = awaitingService ?? throw new ArgumentNullException(nameof(awaitingService));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
            this.DefaultSearchConditions = new ReadOnlyCollection <(string key, object value)>(elementFactory.GetDefaultSearchConditions(this.GetType()).ToList());
        }
示例#8
0
 protected internal ParameterElement(
     IUiItemWrapper itemWrapper,
     IUiNavigationProvider uiNavigationProvider,
     IElementFactory elementFactory,
     IAwaitingService awaitingService,
     ILogger logger)
     : base(
         itemWrapper,
         uiNavigationProvider,
         elementFactory,
         awaitingService,
         logger)
 {
     this.awaitingService = awaitingService;
 }
示例#9
0
 internal TextBlockElement(
     IUiItemWrapper itemWrapper,
     IUiNavigationProvider uiNavigationProvider,
     IElementFactory elementFactory,
     IAwaitingService awaitingService,
     ILogger logger)
     : base(
         itemWrapper,
         uiNavigationProvider,
         elementFactory,
         awaitingService,
         logger)
 {
     this.itemWrapper = itemWrapper;
 }
示例#10
0
        public CodedUiUiItemWrapper(
            AutomationElement automationElement,
            IMouseSimulator mouseSimulator,
            IKeyboardSimulator keyboardSimulator,
            ILogger logger,
            ISettings settings,
            IAwaitingService awaitingService)
        {
            this.automationElement = automationElement ?? throw new ArgumentNullException(nameof(automationElement));
            this.mouse             = mouseSimulator ?? throw new ArgumentNullException(nameof(mouseSimulator));
            this.keyboard          = keyboardSimulator ?? throw new ArgumentNullException(nameof(keyboardSimulator));
            this.logger            = logger ?? throw new ArgumentNullException(nameof(logger));
            this.settings          = settings ?? throw new ArgumentNullException(nameof(settings));
            this.awaitingService   = awaitingService ?? throw new ArgumentNullException(nameof(awaitingService));

            this.visualTreeNavigationRetryCount = this.settings.VisualTreeNavigationRetryCount;
        }
示例#11
0
 internal DataGridElement(
     IUiItemWrapper itemWrapper,
     IUiNavigationProvider uiNavigationProvider,
     IElementFactory elementFactory,
     IAwaitingService awaitingService,
     ILogger logger)
     : base(
         itemWrapper,
         uiNavigationProvider,
         elementFactory,
         awaitingService,
         logger)
 {
     this.itemWrapper     = itemWrapper;
     this.awaitingService = awaitingService;
     this.logger          = logger;
 }
示例#12
0
 protected internal ImageElement(
     IUiItemWrapper itemWrapper,
     IUiNavigationProvider uiNavigationProvider,
     IElementFactory elementFactory,
     IAwaitingService awaitingService,
     ILogger logger,
     string screenshotTemporaryFolder = null)
     : base(
         itemWrapper,
         uiNavigationProvider,
         elementFactory,
         awaitingService,
         logger)
 {
     this.logger = logger;
     this.screenshotTemporaryFolder = screenshotTemporaryFolder;
 }
示例#13
0
 internal AppiumElementContext(
     string windowName,
     WindowsDriver <WindowsElement> driver,
     ILogger logger,
     ISettings settings,
     AppiumUiItemWrapperFactory wrapperFactory,
     IAwaitingService awaitingService,
     Action <string> appRootFunction)
 {
     this.WindowName        = windowName;
     this.Settings          = settings;
     this.Driver            = driver;
     this.WrapperFactory    = wrapperFactory;
     this.Logger            = logger;
     this.AwaitingService   = awaitingService;
     this.BringIntoViewFunc = appRootFunction;
 }
        public AppiumUiItemWrapper CreateWrapper(
            WindowsElement element,
            string windowName,
            WindowsDriver <WindowsElement> driver,
            ILogger logger,
            ISettings settings,
            IAwaitingService awaitingService,
            Action <string> appRootFunction)
        {
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (awaitingService == null)
            {
                throw new ArgumentNullException(nameof(awaitingService));
            }

            var context = new AppiumElementContext(windowName, driver, logger, settings, this, awaitingService, appRootFunction);

            // create item wrapper
            var res = new AppiumUiItemWrapper(element, context);

            // return wrapper
            return(res);
        }
示例#15
0
        public T CreateElement <T>(IUiItemWrapper itemWrapper, IUiNavigationProvider uiNavigationProvider, IElementFactory elementFactory, IAwaitingService awaitingService, ILogger logger)
            where T : Element
        {
            var type = typeof(T);

            if (type == typeof(DataGridElement))
            {
                return(new DataGridElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(DataGridRowElement))
            {
                return(new DataGridRowElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(DataGridCellElement))
            {
                return(new DataGridCellElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(TextBlockElement))
            {
                return(new TextBlockElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(TextBoxElement))
            {
                return(new TextBoxElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(TreeViewElement))
            {
                return(new TreeViewElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(TreeViewItemElement))
            {
                return(new TreeViewItemElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(ButtonElement))
            {
                return(new ButtonElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(TabControlElement))
            {
                return(new TabControlElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(TabItemElement))
            {
                return(new TabItemElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(CheckBoxElement))
            {
                return(new CheckBoxElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(ImageElement))
            {
                // todo: make separate configurable folder
                return(new ImageElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger, this.settings.CommunicationLogFolderPathAlias) as T);
            }
            else if (type == typeof(ComboBoxElement))
            {
                return(new ComboBoxElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }
            else if (type == typeof(ListBoxItemElement))
            {
                return(new ListBoxItemElement(itemWrapper, uiNavigationProvider, elementFactory, awaitingService, logger) as T);
            }

            return(default);