Exemple #1
0
        public T CreateSelector <T>(string constructor) where T : Selector, new()
        {
            var t = new T();

            if (Parser.IsId.IsMatch(constructor))
            {
                t.Init(Parser.IsId.Match(constructor).Groups[1].Value,
                       new List <Func <string, IEnumerable <SelectorPrefix>, IWebDriver, IEnumerable <Element> > > {
                    ById
                });
            }
            else if (Parser.IsElement.IsMatch(constructor))
            {
                t.Init(Parser.IsElement.Match(constructor).Groups[1].Value,
                       new List <Func <string, IEnumerable <SelectorPrefix>, IWebDriver, IEnumerable <Element> > > {
                    ByTag
                });
            }
            else if (Parser.IsClass.IsMatch(constructor))
            {
                t.Init(Parser.IsClass.Match(constructor).Groups[1].Value,
                       new List <Func <string, IEnumerable <SelectorPrefix>, IWebDriver, IEnumerable <Element> > > {
                    ByClass
                });
            }
            else if (Parser.IsXPath.IsMatch(constructor))
            {
                t.Init(Parser.IsXPath.Match(constructor).Groups[1].Value,
                       new List <Func <string, IEnumerable <SelectorPrefix>, IWebDriver, IEnumerable <Element> > > {
                    ByXpath
                });
            }
            else if (Selectors.ContainsKey(t.Type) && Selectors[t.Type].Any())
            {
                t.Init(constructor, Selectors[t.Type]);
            }
            else
            {
                throw new GherkinException($"the selector type of '{t.Type}' is not supported.");
            }
            return(t);
        }