Example #1
0
        public void UnavoidableDuplicateTakesFirst()
        {
            // test file should be just two tags that look exactly the same
            Assert.That(_wb.Document != null, "_wb.Document == null");
            HtmlDocument doc  = _wb.Document.OpenNew(true);
            string       html = File.ReadAllText(@"C:\Work\TestRecorder3\tests\html\UnavoidableDuplicates.html");

            if (doc != null)
            {
                doc.Write(html);
            }

            HtmlElementCollection collection = GetInputElements();

            int counter = collection.Cast <HtmlElement>().Count(element => element.GetAttribute("type") == "hidden" && element.GetAttribute("value") == "second");

            Assert.AreEqual(2, counter, "Test not set up properly-- need two tag matches");

            var hiddenElement = collection.Cast <HtmlElement>().FirstOrDefault(element => element.GetAttribute("type") == "hidden" && element.GetAttribute("value") == "second");

            Assert.IsNotNull(hiddenElement, "hiddenElement == null");
            var findCollection = new FindAttributeCollection((IHTMLElement)hiddenElement.DomElement);

            Assert.That(findCollection.AttributeList.Count == 2, "Different attribute count than expected");
            Assert.IsNotNull(findCollection.AttributeList.Find(a => a.FindName == "type"), "does not contain type attribute");
            Assert.IsNotNull(findCollection.AttributeList.Find(a => a.FindName == "value"), "does not contain value attribute");
        }
Example #2
0
        public FindAttributeCollection GuiToObject()
        {
            var           collection = new FindAttributeCollection();
            FindAttribute attribute  = GetFindAttribute();

            collection.Add(attribute);
            return(collection);
        }
 public ScriptProperty(string windowName, string propertyCode, FindAttributeCollection finder = null)
 {
     WindowName   = windowName;
     PropertyCode = propertyCode.Trim();
     if (finder != null)
     {
         Finder = finder;
     }
 }
Example #4
0
        public void GetDescription()
        {
            HtmlElementCollection collection = GetInputElements();
            var element        = (IHTMLElement)collection[0].DomElement;
            var findCollection = new FindAttributeCollection(element);

            findCollection.AttributeList.Add(new FindAttribute("value", "321"));
            Assert.That(findCollection.GetDescription() == "id=name, value=321");
        }
Example #5
0
        public void GetFriendlyNameLong()
        {
            var findCollection = new FindAttributeCollection {
                TagName = "span"
            };

            findCollection.AttributeList.Add(new FindAttribute("name", "thisIsAVeryLongNameThatKeepsOnGoing"));
            Assert.AreEqual(findCollection.FriendlyName, "spanThisisaverylong");
        }
Example #6
0
        public void GetFriendlyNameShort()
        {
            var findCollection = new FindAttributeCollection {
                TagName = "span"
            };

            findCollection.AttributeList.Add(new FindAttribute("name", "itemname"));
            Assert.That(findCollection.FriendlyName == "spanItemname");
        }
Example #7
0
        public void DetermineFinderByInnerText()
        {
            HtmlElementCollection collection = _wb.Document.GetElementsByTagName("a");
            var element = (IHTMLElement)collection[1].DomElement;

            var findCollection = new FindAttributeCollection(element);

            Assert.AreEqual(5, findCollection.AttributeList.Count, "Find List count not working");
            Assert.That(findCollection.AttributeList.Exists(a => a.FindName == "Text"));
        }
Example #8
0
        public void DetermineFinderById()
        {
            HtmlElementCollection collection = GetInputElements();
            var element = (IHTMLElement)collection[0].DomElement;

            var findCollection = new FindAttributeCollection(element);

            Assert.AreEqual(1, findCollection.AttributeList.Count, "Find List count not working");
            Assert.AreEqual("id", findCollection.AttributeList[0].FindName);
        }
Example #9
0
        public void DetermineFinderForNoNameOrId()
        {
            HtmlElementCollection collection = GetInputElements();

            // get the first hidden element
            var hiddenElement = collection.Cast <HtmlElement>().FirstOrDefault(element => element.GetAttribute("type") == "hidden");

            Assert.IsNotNull(hiddenElement, "hiddenElement == null");
            var findCollection = new FindAttributeCollection((IHTMLElement)hiddenElement.DomElement);

            Assert.AreEqual(2, findCollection.AttributeList.Count, "More attributes than expected");
            Assert.AreEqual("value", findCollection.AttributeList[0].FindName, "Not found on value");
        }
Example #10
0
        /// <summary>
        /// ensures that the friendly name is unique among the properties
        /// </summary>
        /// <param name="finder">attribute collection to create the name from</param>
        /// <returns>verified friendly name</returns>
        internal string GetUniqueFriendlyName(FindAttributeCollection finder)
        {
            string friendlyName = finder.FriendlyName;
            string verifiedName = friendlyName;
            int    counter      = 1;

            while (_usedFriendlyNames.Exists(n => n.FriendlyName == verifiedName))
            {
                verifiedName = friendlyName + (counter++);
            }
            _usedFriendlyNames.Add(finder);
            return(verifiedName);
        }
Example #11
0
        /// <summary>
        /// creates a finder string for action object
        /// </summary>
        /// <param name="finder">list of finder attributes necessary to locate this element in the DOM</param>
        /// <returns>WatiN-suitable finder string</returns>
        public override string GetPropertyAttributeString(FindAttributeCollection finder)
        {
            var builder = new StringBuilder();

            foreach (FindAttribute attribute in finder.AttributeList)
            {
                string findName = attribute.FindName.ToLower();
                if (findName == "href")
                {
                    findName = "url";
                }
                builder.AppendFormat(" {0}=\"{1}\"", findName, attribute.FindValue);
            }
            return(builder.ToString());
        }
Example #12
0
        public void FindOnDuplicateName()
        {
            HtmlElementCollection collection = GetInputElements();

            // get the first hidden element
            var radioElement = collection.Cast <HtmlElement>().FirstOrDefault(element => element.GetAttribute("type") == "radio");

            Assert.IsNotNull(radioElement, "radioElement == null");

            // set the pattern to exclude id
            var pattern = new List <string> {
                "name", "title", "href", "url", "src", "value", "style", "text"
            };
            var findCollection = new FindAttributeCollection((IHTMLElement)radioElement.DomElement, pattern);

            Assert.That(findCollection.AttributeList.Count >= 2, "Different attribute count than expected");
            Assert.IsNotNull(findCollection.AttributeList.Find(a => a.FindName == "name"), "does not contain name attribute");
            Assert.IsNotNull(findCollection.AttributeList.Find(a => a.FindName == "value"), "does not contain value attribute");
        }
Example #13
0
        /// <summary>
        /// makes a string out of a command
        /// </summary>
        /// <param name="elementName">object to command</param>
        /// <param name="nvcAttributes">parameters to the command</param>
        /// <returns>code line string</returns>
        private string CommandToString(string elementName, FindAttributeCollection finder, NameValueCollection nvcAttributes)
        {
            var builder = new StringBuilder();

            builder.Append("<");
            builder.Append(elementName);

            if (finder != null)
            {
                builder.Append(GetPropertyAttributeString(finder));
            }

            foreach (string key in nvcAttributes)
            {
                builder.Append(" " + key + "=\"" + nvcAttributes[key] + "\"");
            }

            builder.Append("/>");

            return(builder.ToString());
        }
Example #14
0
        /// <summary>
        /// creates a finder string for action object
        /// </summary>
        /// <param name="finder">list of finder attributes necessary to locate this element in the DOM</param>
        /// <returns>WatiN-suitable finder string</returns>
        public override string GetPropertyAttributeString(FindAttributeCollection finder)
        {
            var builder = new StringBuilder();

            foreach (FindAttribute attribute in finder.AttributeList)
            {
                string findName = attribute.FindName.ToLower();
                switch (findName)
                {
                case "alt":
                    findName = "Find.ByAlt(\"{0}\")";
                    break;

                case "class":
                    findName = "Find.ByClass(\"{0}\")";
                    break;

                case "for":
                    findName = "Find.ByFor(\"{0}\")";
                    break;

                case "id":
                    findName = "Find.ById(\"{0}\")";
                    break;

                case "name":
                    findName = "Find.ByName(\"{0}\")";
                    break;

                case "text":
                    findName = "Find.ByText(\"{0}\")";
                    break;

                case "url":
                case "href":
                    findName = "Find.ByUrl(\"{0}\")";
                    break;

                case "title":
                    findName = "Find.ByTitle(\"{0}\")";
                    break;

                case "value":
                    findName = "Find.ByValue(\"{0}\")";
                    break;

                case "src":
                    findName = "Find.BySrc(\"{0}\")";
                    break;

                default:
                    findName = "Find.By(\"{0}\",\"{1}\")";
                    break;
                }
                if (findName.Contains("{1}"))
                {
                    builder.AppendFormat(findName + " && ", attribute.FindName, attribute.FindValue);
                }
                else
                {
                    builder.AppendFormat(findName + " && ", attribute.FindValue);
                }
            }
            builder = builder.Remove(builder.Length - 4, 4);
            return(builder.ToString());
        }
Example #15
0
 public abstract string GetPropertyAttributeString(FindAttributeCollection finder);
Example #16
0
        /// <summary>
        /// creates a finder string for action object
        /// </summary>
        /// <param name="finder">list of finder attributes necessary to locate this element in the DOM</param>
        /// <returns>WatiN-suitable finder string</returns>
        public override string GetPropertyAttributeString(FindAttributeCollection finder)
        {
            var builder = new StringBuilder();

            foreach (FindAttribute attribute in finder.AttributeList)
            {
                string findName = attribute.FindName.ToLower();
                switch (findName)
                {
                case "alt":
                    findName = ":alt => \"{0}\"";
                    break;

                case "class":
                    findName = ":class => \"{0}\"";
                    break;

                case "for":
                    findName = ":for => \"{0}\"";
                    break;

                case "id":
                    findName = ":id => \"{0}\"";
                    break;

                case "name":
                    findName = ":name => \"{0}\"";
                    break;

                case "text":
                    findName = ":text => \"{0}\"";
                    break;

                case "url":
                case "href":
                    findName = ":url => \"{0}\"";
                    break;

                case "title":
                    findName = ":title => \"{0}\"";
                    break;

                case "value":
                    findName = ":value => \"{0}\"";
                    break;

                case "src":
                    findName = ":src => \"{0}\"";
                    break;

                default:
                    findName = ":\"{0}\" => \"{1}\"";
                    break;
                }
                if (findName.Contains("{1}"))
                {
                    builder.AppendFormat(findName + ", ", attribute.FindName, attribute.FindValue);
                }
                else
                {
                    builder.AppendFormat(findName + ", ", attribute.FindValue);
                }
            }
            builder = builder.Remove(builder.Length - 2, 2);
            return(builder.ToString());
        }