Example #1
0
        public static WebElementInfo CreateInfoFromModel(WebElementViewModel model)
        {
            WebElementInfo info = null;

            if (model is WebContextViewModel webContext)
            {
                info = new WebContext();
                webContext.FillInfo(info);
            }
            else if (model is DropDownElementViewModel dropDown)
            {
                info = new DropDownElementInfo();
                dropDown.FillInfo(info);
            }
            else if (model is RadioGroupViewModel radioGroup)
            {
                info = new RadioGroupElementInfo();
                radioGroup.FillInfo(info);
            }
            else if (model is CombinedElementViewModel combined)
            {
                info = new CombinedWebElementInfo();
                combined.FillInfo(info);
            }
            else
            {
                info = new WebElementInfo();
                model.FillInfo(info);
            }

            return(info);
        }
        public static WebContextInfo GenerateContext(int orderNumber, int elsCount)
        {
            var i = orderNumber;

            var wc = new WebContextInfo
            {
                Name        = $"Context {i}",
                Description = $"Description for context {i}",
                Tags        = new List <string> {
                    $"tag{i}", "contextTag"
                },
                Elements = new List <WebElementInfo>(),
                Locator  = new WebLocatorInfo {
                    LocatorValue = "."
                }
            };

            for (int j = 1; j < elsCount; j++)
            {
                if (j != 2)
                {
                    var c = new CombinedWebElementInfo
                    {
                        Name        = $"Control {i}_{j}",
                        Description = $"Description for control {i}_{j}",
                        Tags        = new List <string> {
                            $"tag{j}", "controlTag"
                        },
                        Elements = new List <WebElementInfo>(),
                        Parent   = wc,
                        Locator  = new WebLocatorInfo {
                            LocatorValue = "./div[@id='control']", IsRelative = true
                        }
                    };
                    wc.Elements.Add(c);


                    var dd = new DropDownElementInfo
                    {
                        Name        = $"DropDown {i}_{j}",
                        Description = $"Description for DropDown {i}_{j}",
                        Tags        = new List <string> {
                            $"tag{j}", "controlTag"
                        },
                        Parent  = wc,
                        Locator = new WebLocatorInfo {
                            LocatorValue = "./div[@id='control']", IsRelative = true
                        },
                        Elements = new List <WebElementInfo>()
                    };
                    wc.Elements.Add(dd);
                    dd.Elements.Add(new WebElementInfo
                    {
                        Name        = $"DropDown {i}_{j} Input",
                        Description = $"Description for DropDown {i}_{j} Input",
                        Tags        = new List <string> {
                            $"tag{j}", "controlTag"
                        },
                        Parent  = wc,
                        Locator = new WebLocatorInfo {
                            LocatorValue = "./div[@id='control']", IsRelative = true
                        },
                        InnerKey = DropDownElementInfo.Keys.Input
                    });
                    dd.Elements.Add(new WebElementInfo
                    {
                        Name        = $"DropDown {i}_{j} Option",
                        Description = $"Description for DropDown {i}_{j} Option",
                        Tags        = new List <string> {
                            $"tag{j}", "controlTag"
                        },
                        Parent  = wc,
                        Locator = new WebLocatorInfo {
                            LocatorValue = "./div[@id='control']", IsRelative = true
                        },
                        InnerKey = DropDownElementInfo.Keys.Option
                    });

                    var rg = new DropDownElementInfo
                    {
                        Name        = $"RadioGroup {i}_{j}",
                        Description = $"Description for RadioGroup {i}_{j}",
                        Tags        = new List <string> {
                            $"tag{j}", "controlTag"
                        },
                        Parent  = wc,
                        Locator = new WebLocatorInfo {
                            LocatorValue = "./div[@id='control']", IsRelative = true
                        },
                        Elements = new List <WebElementInfo>()
                    };
                    wc.Elements.Add(rg);
                    rg.Elements.Add(new WebElementInfo
                    {
                        Name        = $"DropDown {i}_{j} Option",
                        Description = $"Description for RadioGroup {i}_{j} Option",
                        Tags        = new List <string> {
                            $"tag{j}", "controlTag"
                        },
                        Parent  = wc,
                        Locator = new WebLocatorInfo {
                            LocatorValue = "./div[@id='control']", IsRelative = true
                        },
                        InnerKey = RadioGroupElementInfo.Keys.Option
                    });

                    for (int k = 1; k < 5; k++)
                    {
                        var e = new WebElementInfo
                        {
                            Name        = $"Element {i}_{j}_{k}",
                            Description = $"Description for element {i}_{j}_{k}",
                            Tags        = new List <string> {
                                $"tag{j}", "elementTag"
                            },
                            Parent  = c,
                            Locator = new WebLocatorInfo {
                                LocatorValue = "./input[@id='input']", IsRelative = true
                            }
                        };
                        c.Elements.Add(e);
                    }
                }
                else
                {
                    var e = new WebElementInfo
                    {
                        Name        = $"Element {i}_{j}",
                        Description = $"Description for element {i}_{j}",
                        Tags        = new List <string> {
                            $"tag{j}", "elementTag"
                        },
                        Parent  = wc,
                        IsKey   = true,
                        Locator = new WebLocatorInfo {
                            LocatorValue = "./input[@id='input']", IsRelative = true
                        }
                    };
                    wc.Elements.Add(e);
                }
            }

            return(wc);
        }
        public static WebElementInfo CreateInfoFromModel(WebElementInfoViewModel model, CombinedWebElementInfo parent = null)
        {
            WebElementInfo info = null;

            switch (model)
            {
            case WebElementWithReferenceViewModel wr:
            {
                var innerInfo = CreateInfoFromModel(wr.ReferencedWebElement);

                switch (wr.ElementType)
                {
                case WebElementTypes.Frame:

                    var f = new FrameWebElementInfo();
                    f.TreePathToInnerElement = wr.ReferenceBreadString;
                    innerInfo.Parent         = f;
                    f.InnerElement           = innerInfo;
                    info = f;

                    break;

                case WebElementTypes.Reference:

                    var r = new WebElementReference();
                    r.TreePathToReferencedElement = wr.ReferenceBreadString;
                    innerInfo.Parent    = r;
                    r.ReferencedElement = innerInfo;
                    info = r;

                    break;

                default:
                    throw new Exception($"Unexpected WebElementWithReferenceViewModel ElementType: {wr.ElementType}");
                }
            }
            break;


            case CombinedWebElementInfoViewModel combinedModel:
            {
                CombinedWebElementInfo combined = null;
                switch (combinedModel.ElementType)
                {
                case WebElementTypes.Context:
                    combined = new WebContextInfo();
                    break;

                case WebElementTypes.DropDown:
                    combined = new DropDownElementInfo();
                    break;

                case WebElementTypes.RadioGroup:
                    combined = new RadioGroupElementInfo();
                    break;

                case WebElementTypes.Directory:
                    combined = new WebElementsDirectory();
                    break;

                case WebElementTypes.Control:
                    combined = new CombinedWebElementInfo();
                    break;

                case WebElementTypes.Page:
                {
                    var wpModel = model as WebPageInfoViewModel;
                    var wpInfo  = new WebPageInfo();
                    wpInfo.DefaultUrl     = wpModel.DefaultUrl;
                    wpInfo.UrlRegexString = wpModel.UrlRegexString;
                    combined = wpInfo;
                }
                break;

                default:
                    throw new Exception($"Unexpected combinedModel.ElementType: {combinedModel.ElementType}");
                }
                info = combined;
                combined.Elements = combinedModel.Elements
                                    ?.Select(em => CreateInfoFromModel(em, combined))
                                    .ToList();
            }
            break;

            default:
                info = new WebElementInfo();
                break;
            }

            info.Name        = model.Name;
            info.Description = model.Description;
            info.InnerKey    = model.InnerKey;
            info.Tags        = model.Tags?.ToList();
            info.Locator     = model.Locator?.GetLocatorInfo();
            info.IsKey       = model.IsKey;
            info.Parent      = parent;

            return(info);
        }