コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CodedUIListElementWrapper{TElement, TChildElement}" /> class.
        /// </summary>
        /// <param name="parentElement">The parent element.</param>
        /// <param name="webBrowser">The browser.</param>
        public CodedUIListElementWrapper(TElement parentElement, IBrowser webBrowser)
            : base(parentElement, webBrowser)
        {
            this.builderFunc = PageBuilder <TElement, TChildElement> .CreateElement(typeof(TChildElement));

            this.lockObject = new object();

            this.ValidateElementExists = true;
        }
コード例 #2
0
ファイル: CodedUIBrowser.cs プロジェクト: pliekhus/specbind
        /// <summary>
        /// Creates the native page.
        /// </summary>
        /// <param name="pageType">Type of the page.</param>
        /// <returns>The internal document.</returns>
        private HtmlDocument CreateNativePage(Type pageType)
        {
            Func <UITestControl, IBrowser, Action <HtmlControl>, HtmlDocument> function;

            if (!this.pageCache.TryGetValue(pageType, out function))
            {
                function = PageBuilder <UITestControl, HtmlDocument> .CreateElement(pageType);

                this.pageCache.Add(pageType, function);
            }

            UITestControl parentElement = this.window.Value;

            // Check to see if a frames reference exists
            var isFrameDocument = false;
            PageNavigationAttribute navigationAttribute;

            if (pageType.TryGetAttribute(out navigationAttribute) &&
                !string.IsNullOrWhiteSpace(navigationAttribute.FrameName))
            {
                Func <UITestControl, HtmlFrame> frameFunction;
                if (!this.frameCache.Value.TryGetValue(navigationAttribute.FrameName, out frameFunction))
                {
                    throw new PageNavigationException(
                              "Cannot locate frame with ID '{0}' for page '{1}'",
                              navigationAttribute.FrameName,
                              pageType.Name);
                }

                parentElement   = frameFunction(parentElement);
                isFrameDocument = true;

                if (parentElement == null)
                {
                    throw new PageNavigationException(
                              "Cannot load frame with ID '{0}' for page '{1}'. The property that matched the frame did not return a parent document.",
                              navigationAttribute.FrameName,
                              pageType.Name);
                }
            }

            var documentElement = function(parentElement, this, null);

            if (isFrameDocument)
            {
                // Set properties that are relevant to the frame.
                documentElement.SearchProperties[HtmlDocument.PropertyNames.FrameDocument]   = "True";
                documentElement.SearchProperties[HtmlDocument.PropertyNames.RedirectingPage] = "False";
            }

            return(documentElement);
        }
コード例 #3
0
        /// <summary>
        /// Creates the frame cache from the currently loaded types in the project.
        /// </summary>
        /// <returns>The created frame cache.</returns>
        private static Dictionary <string, Func <UITestControl, HtmlFrame> > GetFrameCache()
        {
            var frames = new Dictionary <string, Func <UITestControl, HtmlFrame> >(StringComparer.OrdinalIgnoreCase);

            foreach (var frameType in GetFrameTypes())
            {
                // Check the properties for ones that can produce a frame.
                foreach (var property in frameType.GetProperties()
                         .Where(p => typeof(HtmlFrame).IsAssignableFrom(p.PropertyType) && p.CanRead && !frames.ContainsKey(p.Name)))
                {
                    frames.Add(property.Name, PageBuilder <UITestControl, HtmlFrame> .CreateFrameLocator(frameType, property));
                }
            }

            return(frames);
        }
コード例 #4
0
ファイル: PageBuilder.cs プロジェクト: scottcowan/specbind
        /// <summary>
        /// Creates the frame locator method to help load that from a property.
        /// </summary>
        /// <param name="frameType">Type of the class that will provide the frame.</param>
        /// <param name="property">The property on the class that should be accessed to provide the frame.</param>
        /// <returns>The function used to create the document.</returns>
        public static Func <TParent, TOutput> CreateFrameLocator(Type frameType, PropertyInfo property)
        {
            var builder = new PageBuilder <TParent, TOutput>();

            return(builder.CreateFrameLocatorInternal(frameType, property));
        }
コード例 #5
0
ファイル: PageBuilder.cs プロジェクト: scottcowan/specbind
        /// <summary>
        /// Creates the page.
        /// </summary>
        /// <param name="elementType">Type of the page.</param>
        /// <returns>The page builder function.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the constructor is invalid.</exception>
        public static Func <TParent, IBrowser, Action <HtmlControl>, TOutput> CreateElement(Type elementType)
        {
            var builder = new PageBuilder <TParent, TOutput>();

            return(builder.CreateElementInternal(elementType));
        }