public static HtmlTag AddFieldLabel(HtmlTag tag, ModelInfo info)
 {
     var label=new SpanTag().Text(info.Name).AddClass("display-label");
     //if (tag.HasChild<LabelTag>()) return tag;
     //var label = info.ConventionsRegistry().Labels.GenerateTags(info);
     tag.WrapWith(HtmlTag.Placeholder()).InsertFirst(label);
     return tag.Parent;
 }
Ejemplo n.º 2
0
        public static HtmlTag AddFieldLabel(HtmlTag tag, ModelInfo info)
        {
            var label = new SpanTag().Text(info.Name).AddClass("display-label");

            //if (tag.HasChild<LabelTag>()) return tag;
            //var label = info.ConventionsRegistry().Labels.GenerateTags(info);
            tag.WrapWith(HtmlTag.Placeholder()).InsertFirst(label);
            return(tag.Parent);
        }
Ejemplo n.º 3
0
        public VModelSection(WebElement vmodelsection, bool parseLinks = false)
        {
            var rows    = vmodelsection.FindSingle <TBodyTag>("./table/tbody/");
            var row     = rows.FindChildren <TrTag>();
            int licznik = row.Count;

            if (row.Last().FindChildren <TdTag>().Last().FindDescendants <SpanTag>().Count > 0)
            {
                licznik     = licznik - 1;
                zmienButton = rows.FindSingle <SpanTag>(".//span[@innertext='Zmień']");
            }

            for (int i = 0; i < licznik; i++)
            {
                var columns    = row[i].FindChildren <TdTag>();
                var labelcount = row[i].FindDescendants <LabelTag>().Count;
                if (labelcount != 0)
                {
                    if (columns.Count != 2)
                    {
                        throw new Exception("To nie jest VMODELSECTION");
                    }
                    var label = columns[0].FindChild <LabelTag>();
                    var value = columns[1].FindChild <LabelTag>();
                    if (label != null && value != null)
                    {
                        var valueFromLabel = value.InnerText.Trim();
                        if (parseLinks)
                        {
                            var aTags = value.FindDescendants <ATag>();
                            if (aTags.Count > 0)
                            {
                                valueFromLabel = aTags[0].InnerText;
                            }
                        }
                        var vfields = new VModelFileds {
                            Label = label.InnerText.Trim(), Value = valueFromLabel
                        };
                        _fields.Add(vfields);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void CheckLanguage()
        {
            string osLanguage = Utils.GetOSLanguage().TwoLetterISOLanguageName;

            //string regionStr = Utils.GetCurrentGEOLocationCountry().Trim();

            Report.Log(ReportLevel.Info, "The current OS Language is " + osLanguage);
            //Report.Log(ReportLevel.Info, "The current Region is " + regionStr);

//          var countryCodesMapping = new Dictionary<string, RegionInfo>();
//          CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
//            foreach (var culture in cultures)
//            {
//              var region = new RegionInfo(culture.LCID);
//              countryCodesMapping[region.EnglishName] = region;
//            }

            //string regionCode = countryCodesMapping[regionStr].TwoLetterISORegionName.ToLower();
            //Report.Log(ReportLevel.Info, "The region code is: " + regionCode);

            SpanTag body = Host.Local.FindSingle <SpanTag>(@"/dom//h1[#'pspagetitle']/span", 5000);
//
            string articleText = DHSArticle.StripHTML(body.GetInnerHtml());

            Report.Log(ReportLevel.Info, "The text present is `" + articleText + "`");

            Dictionary <string, float> detectedLanguages = Utils.InWhichLanguages(articleText);
            string languageCode = detectedLanguages.Keys.First();

            Report.Log(ReportLevel.Info, "The detected language is " + languageCode);

            //url = "http://www.dell.com/support/home/" + regionCode + "/" + languageCode + "/vnbsdt1/product-support/servicetag/5RQTQX1";
            string langUrl = url.Substring("http://www.dell.com/support/home/".Length + 3, 2);

            //string expectedUrl = "http://www.dell.com/support/home/" + regionCode + "/" + languageCode;
            Ranorex.Validate.AreEqual(langUrl, osLanguage.Equals("ko")? "en" : osLanguage);
            Report.Log(ReportLevel.Info, langUrl);
        }
Ejemplo n.º 5
0
        public static string ConvertToUbb(string htmlContent, ContentConvert beforeConvert, ContentConvert afterConvert)
        {
            string msg = string.Empty;

            htmlContent = htmlContent.Replace("\n", string.Empty);
            htmlContent = htmlContent.Replace("\r", string.Empty);
            htmlContent = regScript.Replace(htmlContent, string.Empty);
            htmlContent = regStyle.Replace(htmlContent, string.Empty);
            // htmlContent = htmlContent.Trim();

            if (beforeConvert != null)
            {
                htmlContent = beforeConvert(htmlContent);
            }

            MatchCollection matchs   = regTag.Matches(htmlContent);
            int             tagIndex = 0;

            List <HtmlTagBase> tags = new List <HtmlTagBase>()
            , beginTags             = new List <HtmlTagBase>()
            , endTages   = new List <HtmlTagBase>()
            , singleTags = new List <HtmlTagBase>();

            foreach (Match m in matchs)
            {
                HtmlTagBase t;
                string      tagName = m.Groups[1].Value;

                //这里也可以根据HTML标签来反射生成Html标签类, 代码可以少很多, 但是这样性能不好。
                switch (tagName.ToLower())
                {
                case "img":
                    t = new ImgTag(tagIndex, m.Value, m.Index);
                    break;

                case "a":
                    t = new ATag(tagIndex, m.Value, m.Index);
                    break;

                case "font":
                    t = new FontTag(tagIndex, m.Value, m.Index);
                    break;

                case "span":
                    t = new SpanTag(tagIndex, m.Value, m.Index);
                    break;

                case "br":
                    t = new BrTag(tagIndex, m.Value, m.Index);
                    break;

                case "div":
                    t = new DivTag(tagIndex, m.Value, m.Index);
                    break;

                case "p":
                    t = new PTag(tagIndex, m.Value, m.Index);
                    break;

                case "table":
                    t = new TableTag(tagIndex, m.Value, m.Index);
                    break;

                case "ol":
                case "ul":
                    t = new ListTag(tagIndex, m.Value, m.Index);
                    break;

                case "td":
                case "tr":
                case "s":
                case "b":
                case "i":
                case "sub":
                case "sup":
                case "u":
                    t = new PairTag(tagIndex, m.Value, m.Index);
                    break;

                case "th":
                    t = new PairTag(tagIndex, m.Value, m.Index);
                    ((PairTag)t).UbbTag = "td";
                    break;

                case "strong":
                    t = new PairTag(tagIndex, m.Value, m.Index);
                    ((PairTag)t).UbbTag = "b";
                    break;

                case "em":
                    t = new PairTag(tagIndex, m.Value, m.Index);
                    ((PairTag)t).UbbTag = "i";
                    break;

                case "strike":
                    t = new PairTag(tagIndex, m.Value, m.Index);
                    ((PairTag)t).UbbTag = "s";
                    break;

                case "blockquote":
                    t = new PairTag(tagIndex, m.Value, m.Index);
                    ((PairTag)t).UbbTag = "indent";
                    break;

                case "h1":
                case "h2":
                case "h3":
                case "h4":
                case "h5":
                case "h6":
                    t = new HTag(tagIndex, m.Value, m.Index);
                    break;

                case "embed":
                    t = new EmbedTag(tagIndex, m.Value, m.Index);
                    break;

                default:
                    t = new HtmlTagBase(tagIndex, m.Value, m.Index);
                    break;
                }
                tagIndex++;

                t.TagList = tags;
                tags.Add(t);

                if (t.IsSingleTag)
                {
                    singleTags.Add(t);
                }
                else
                {
                    if (!t.IsEndTag)
                    {
                        beginTags.Add(t);
                    }
                    else
                    {
                        int flag = -1;
                        for (int i = beginTags.Count - 1; i >= 0; i--)
                        {
                            if (beginTags[i].TagName == t.TagName)//匹配开始标记和结束标记
                            {
                                flag = i;
                                beginTags[i].Pair = t;
                                t.Pair            = beginTags[i];
                                break;
                            }
                        }

                        if (flag >= 0)
                        {
                            for (int i = beginTags.Count - 1; i >= flag; i--)
                            {
                                beginTags.RemoveAt(i);
                            }
                        }
                    }
                }
            }

            StringBuilder builder = new StringBuilder(htmlContent);

            for (int i = 0; i < tags.Count; i++)
            {
                if (!tags[i].IsSingleTag)
                {
                    if (tags[i].Pair == null)
                    {
                        msg += tags[i].TagName + "没有对应的" + (tags[i].IsEndTag ? "开始" : "结束") + "标记\r\n";
                    }
                }
                if (!tags[i].IsEndTag || tags[i].IsSingleTag)
                {
                    builder = tags[i].ConvertToUBB(builder);
                }
            }

            //builder.Replace(" ", string.Empty);
            builder.Replace("\t", string.Empty);

            htmlContent = builder.ToString();
            htmlContent = new Regex("<.*?>").Replace(htmlContent, string.Empty);
            htmlContent = HttpUtility.HtmlDecode(htmlContent);


            if (afterConvert != null)
            {
                htmlContent = afterConvert(htmlContent);
            }

            return(htmlContent);
        }