public static ISelector GetSelector(ExtractBy extractBy)
 {
     string value = extractBy.Value;
     ISelector selector;
     switch (extractBy.Type)
     {
         case ExtractBy.ExtracType.Css:
             selector = new CssSelector(value);
             break;
         case ExtractBy.ExtracType.Regex:
             selector = new RegexSelector(value);
             break;
         case ExtractBy.ExtracType.XPath:
             selector = GetXpathSelector(value);
             break;
         case ExtractBy.ExtracType.JsonPath:
             selector = new JsonPathSelector(value);
             break;
         case ExtractBy.ExtracType.Enviroment:
             selector = new EnviromentSelector(value);
             break;
         default:
             selector = GetXpathSelector(value);
             break;
     }
     return selector;
 }
        public void TestJsonPath()
        {
            JsonPathSelector jsonPathSelector = new JsonPathSelector("$.store.book[*].author");
            string select = jsonPathSelector.Select(_text);
            IList<string> list = jsonPathSelector.SelectList(_text);
            Assert.AreEqual(select, "Nigel Rees");
            Assert.IsTrue(list.Contains("Nigel Rees"));
            Assert.IsTrue(list.Contains("Evelyn Waugh"));

            jsonPathSelector = new JsonPathSelector("$.store.book[?(@.category == 'reference')]");
            list = jsonPathSelector.SelectList(_text);
            select = jsonPathSelector.Select(_text);

            //			{
            //				"category": "reference",
            //  "author": "Nigel Rees",
            //  "title": "Sayings of the Century",
            //  "price": 8.95
            //}
            //Assert.AreEqual(select, "{\r\n \"category\":\"reference\",\r\n \"author\":\"Nigel Rees\",\r\n \"title\":\"Sayings of the Century\",\r\n \"price\":8.95\r\n }");
            //Assert.AreEqual(list, "{\"author\":\"Nigel Rees\",\"title\":\"Sayings of the Century\",\"category\":\"reference\",\"price\":8.95}");
        }
Exemple #3
0
        public override ISelectable JsonPath(string path)
        {
            JsonPathSelector jsonPathSelector = new JsonPathSelector(path);

            return(SelectList(jsonPathSelector));
        }
 public override ISelectable JsonPath(string path)
 {
     JsonPathSelector jsonPathSelector = new JsonPathSelector(path);
     return SelectList(jsonPathSelector);
 }
Exemple #5
0
        public override ISelectable JsonPath(string jsonPath)
        {
            JsonPathSelector jsonPathSelector = new JsonPathSelector(jsonPath);

            return(SelectList(jsonPathSelector, GetSourceTexts()));
        }