Ejemplo n.º 1
0
        public void InputText(string Tvalue, string Target, string sType)
        {
            //Deal with Command
            List <string> Itmes = JSupport.ComandParse(ref Tvalue, ref Target, ref sType);

            //Action
            foreach (string item in Itmes)
            {
                switch (item)
                {
                case "@普通文本框":
                    element = JElement.GetInputElement(driver, Tvalue, Target);
                    break;

                case "@文件文本框":
                    element = JElement.GetFileInputElement(driver, Tvalue, Target);
                    break;

                case "@清空":
                    JAction.Clear(element);
                    break;

                case "@搜索":
                    JAction.EnterAction(driver, element);
                    break;

                case "@输入":
                    JAction.SendKeys(element, Tvalue);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(string.Format("✘:sType命令中不存在:{0},请核对", item));
                }
            }
        }
Ejemplo n.º 2
0
        private void ParseElements(JElement parent, JElement element, int i, string[] parts)
        {
            element.Parent = parent;

            var hasFilter = filterParser.HasFilter(parts[i]);

            if (hasFilter)
            {
                var partItems = filterParser.GetAllParts(parts[i]);
                element.Name = partItems[0];
                for (int pI = 1; pI < partItems.Length; pI++)
                {
                    var indexValue = filterParser.IsIndexFilter(partItems[pI]);
                    if (indexValue != null)
                    {
                        element.HasIndexer = true;
                        element.IndexNo    = indexValue.Value;
                    }
                    else
                    {
                        element.AttributeFilter = attrFilterParser.Parse(partItems[pI]);
                    }
                }
            }
            else
            {
                element.Name = parts[i];
            }

            if (i + 1 < parts.Length)
            {
                element.Child = new JElement();
                ParseElements(element, element.Child, i + 1, parts);
            }
        }
Ejemplo n.º 3
0
 public void InputDateTime(string Tvalue, string Target = null, string sType = null)
 {
     //Get element
     element = JElement.GetDateTimeElement(driver, Target, Tvalue, sType);
     //Set time
     ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].value ='" + Tvalue + "' ", element);
 }
Ejemplo n.º 4
0
        public void Valid(string Tvalue, string sType = null, string Target = null)
        {
            //Deal with Command
            var Itmes = JSupport.ComandParse(ref Tvalue, ref Target, ref sType);

            //Action
            foreach (string item in Itmes)
            {
                switch (item)
                {
                case "@弹出框校验":
                    JValid.ValidAlert(driver, Tvalue);
                    break;

                case "@文本":
                    element = JElement.GetValidXpath(driver, Tvalue, Target);
                    break;

                case "@对比":
                    if (!element.Text.Contains(Tvalue))
                    {
                        throw new Exception(string.Format("✘:文本校验失败,请检查文本:{0}", Tvalue));
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(string.Format("✘:sType命令中不存在:{0},请核对", Itmes));
                }
            }
        }
Ejemplo n.º 5
0
 public static Stream Encode(this IJsonEncoder encoder, JElement jsonElement, Encoding encoding = null, bool pretty = false)
 {
     var stream = new MemoryStream();
     encoder.Encode(jsonElement, stream, encoding, pretty);
     stream.Position = 0;
     return stream;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Extract data from given source data
        /// </summary>
        /// <param name="source">Source data</param>
        /// <param name="element">Element containing the properties of how data is extracted</param>
        /// <returns>Extracted data depending on given source data type and extraction properties</returns>
        public object SelectData(IDictionary <string, object> source, JElement element)
        {
            if (source.Keys.Contains(element.Name))
            {
                var selectedItem = source[element.Name];
                if (selectedItem is SimpleJson.JsonArray)
                {
                    var selectedItems = (SimpleJson.JsonArray)FilterByAttributes(selectedItem, element.AttributeFilter);
                    if (element.HasIndexer)
                    {
                        if (selectedItems.Count > element.IndexNo.Value)
                        {
                            return(selectedItems[element.IndexNo.Value]);
                        }
                    }
                    else
                    {
                        return(selectedItems);
                    }
                }
                else if (selectedItem is IDictionary <string, object> )
                {
                    return(FilterByAttributes(selectedItem, element.AttributeFilter));
                }
                else
                {
                    return(selectedItem);
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        public void SelectOption(string Tvalue, string Target, string sType)
        {
            //Deal with Command
            var           Itmes        = JSupport.ComandParse(ref Tvalue, ref Target, ref sType);
            SelectElement SelectOption = null;

            //Action
            foreach (string item in Itmes)
            {
                switch (item)
                {
                case "@传统下拉框":
                    element      = JElement.GetSelectElement(driver, Tvalue, Target);
                    SelectOption = new SelectElement(element);
                    break;

                case "@文本选择":
                    SelectOption.SelectByText(Tvalue);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(string.Format("✘:下拉框命令中不存在:{0},请核对", item));
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Parse given expression and return it in JElement format, which has determined properties for each element of expression
        /// </summary>
        /// <param name="expression">Expression to be parsed</param>
        /// <returns>Parsed element metadata</returns>
        public JElement ParseExpression(string expression)
        {
            JElement element = new JElement();

            var parts = expression.Split(PartSeparator);

            ParseElements(null, element, 0, parts);

            return(element);
        }
Ejemplo n.º 9
0
 public void should_encode_field_names_with_non_alpha_numeric_chars()
 {
     var element = new JElement(ElementType.Object);
     element.AddValueMember("$field", "hai");
     #if __MonoCS__
     // Broken in mono as of 2.10.8.1
     // https://bugzilla.xamarin.com/show_bug.cgi?id=18105
     #else
     _encoder.Encode(element).ShouldEqual("{\"$field\":\"hai\"}");
     #endif
 }
Ejemplo n.º 10
0
 private XElement CreateElement(bool isArrayItem, JElement jsonElement, XElement xmlElement)
 {
     var name = isArrayItem ? XmlJson.ArrayItemElementName : jsonElement.Name;
     if (isArrayItem || name.IsValidXmlName()) return xmlElement.CreateElement(name);
     XNamespace @namespace = XmlJson.ArrayItemElementName;
     var child = new XElement(
         @namespace + XmlJson.ArrayItemElementName,
         new XAttribute(XNamespace.Xmlns + "a", XmlJson.ArrayItemElementName),
         new XAttribute(XmlJson.ArrayItemElementName, name));
     xmlElement.Add(child);
     return child;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Parses the specified tokens.
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        /// <returns>
        /// A new element.
        /// </returns>
        public JElement Parse(TokenStream tokens)
        {
            this.tag        = "div";
            this.id         = null;
            this.classes    = new List <string>();
            this.attributes = new List <JElement>();
            this.content    = null;
            var elements = new List <JElement>();

            if (tokens.Is(TokenType.Word))
            {
                this.tag = tokens.Get();
            }

            this.ParseClasses(tokens);
            this.ParseAttributes(tokens);
            this.ParseClasses(tokens);

            ////if (tokens.Is(JadeTokenType.InlineValue))
            ////{
            ////    content = new JExpression(tokens.GetLine().AsString());
            ////}
            ////else if (tokens.Is(TokenType.WhiteSpace))
            ////{
            ////    tokens.Consume();
            ////    content = new JText(tokens.GetLine().AsString());
            ////}
            ////else if (tokens.Is(JadeTokenType.Block))
            ////{
            ////    tokens.Consume();
            ////    content = new JText(GetBlock(tokens, indent));
            ////}
            ////else if (tokens.Is(JadeTokenType.Colon))
            ////{
            ////    tokens.Consume();
            ////    tokens.GetAny(TokenType.WhiteSpace);
            ////    elements.Add(Produce(tokens, indent));
            ////}
            ////else
            ////{
            ////    if (tokens.Is(TokenType.WhiteSpace))
            ////    {
            ////        tokens.Get();
            ////    }

            ////    tokens.GetAny(JadeTokenType.NewLine);
            ////    elements.AddRange(tokens.GetItems(indent));
            ////}

            return(new JTag(this.tag, this.id, this.classes, this.attributes, this.content, elements));
        }
Ejemplo n.º 12
0
        public void should_add_value_array_elements_with_explicit_values()
        {
            var element = new JElement(ElementType.Array);
            element.AddArrayValueElement(true);
            element.AddArrayValueElement(5);
            element.AddArrayValueElement("hai");
            element.AddArrayValueElement(null);

            element.Count().ShouldEqual(4);
            var elements = element.ToList();
            elements[0].ShouldBeAJsonBoolValueArrayElement(true);
            elements[1].ShouldBeAJsonNumberValueArrayElement(5);
            elements[2].ShouldBeAJsonStringValueArrayElement("hai");
            elements[3].ShouldBeAJsonNullValueArrayElement();
        }
Ejemplo n.º 13
0
        public void ButtonClick(string Tvalue, string sType, string Target = null)
        {
            //Deal with Command
            List <string> Itmes = JSupport.ComandParse(ref Tvalue, ref Target, ref sType);

            //Action
            foreach (string item in Itmes)
            {
                switch (item)
                {
                case "@单击":
                    JAction.Click(element);
                    break;

                case "@JS单击":
                    JAction.ClickJS(driver, element);
                    break;

                case "@右击":
                    JAction.RightClick(driver, element);
                    break;

                case "@双击":
                    JAction.DoubleClick(driver, element);
                    break;

                case "@普通按钮":
                    element = JElement.GetBtnElement(driver, Tvalue, Target);
                    break;

                case "@勾选按钮":
                    element = JElement.GetRadioElement(driver, Tvalue, Target);
                    break;

                case "@树节点按钮":
                    element = JElement.GetTreeNodeElement(driver, Tvalue, Target);
                    break;

                case "@图标按钮":
                    element = JElement.GetIConElement(driver, Tvalue, Target);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(string.Format("✘:sType命令中不存在:{0},请核对", Itmes));
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Retrieve item from JSON array at given index
        /// </summary>
        /// <param name="resultsToFilter">JSON array</param>
        /// <param name="element">Element containing index data</param>
        /// <returns>
        /// If item is found with given index, it is returned.
        /// If indexing is not needed or applicable, supplied array is returned.
        /// Otherwise, null is returned.
        /// </returns>
        private object FilterByIndex(object resultsToFilter, JElement element)
        {
            if (resultsToFilter != null && element.HasIndexer && resultsToFilter is SimpleJson.JsonArray)
            {
                var tmpDataItems = resultsToFilter as SimpleJson.JsonArray;
                if (tmpDataItems.Count > element.IndexNo.Value)
                {
                    return(tmpDataItems[element.IndexNo.Value]);
                }
                else
                {
                    return(null);
                }
            }

            return(resultsToFilter);
        }
Ejemplo n.º 15
0
 public void Encode(JElement jsonElement, Stream stream, Encoding encoding = null, bool pretty = false)
 {
     try
     {
         var xmlElement = new XElement(XmlJson.RootElementName);
         Save(jsonElement, xmlElement);
         using (var writer = JsonReaderWriterFactory.CreateJsonWriter(stream, encoding ?? Encoding.UTF8, false, pretty))
         {
             xmlElement.Save(writer);
             writer.Flush();
         }
     }
     catch (Exception exception)
     {
         throw new JsonEncodeException(exception);
     }
 }
Ejemplo n.º 16
0
        public void should_add_fields_with_default_values()
        {
            var element = new JElement(ElementType.Object);
            element.AddMember("field1", ElementType.Boolean);
            element.AddMember("field2", ElementType.Number);
            element.AddMember("field3", ElementType.String);
            element.AddMember("field4", ElementType.Null);
            element.AddMember("field5", ElementType.Object);
            element.AddMember("field6", ElementType.Array);

            element.Count().ShouldEqual(6);
            var fields = element.ToList();
            fields[0].ShouldBeAJsonBoolValueField("field1", false);
            fields[1].ShouldBeAJsonNumberValueField("field2", 0);
            fields[2].ShouldBeAJsonStringValueField("field3", "");
            fields[3].ShouldBeAJsonNullValueField("field4");
            fields[4].ShouldBeAJsonObjectField("field5");
            fields[5].ShouldBeAJsonArrayField("field6");
        }
Ejemplo n.º 17
0
        public void should_add_array_elements_with_default_values()
        {
            var element = new JElement(ElementType.Array);
            element.AddArrayElement(ElementType.Boolean);
            element.AddArrayElement(ElementType.Number);
            element.AddArrayElement(ElementType.String);
            element.AddArrayElement(ElementType.Null);
            element.AddArrayElement(ElementType.Object);
            element.AddArrayElement(ElementType.Array);

            element.Count().ShouldEqual(6);
            var elements = element.ToList();
            elements[0].ShouldBeAJsonBoolValueArrayElement(false);
            elements[1].ShouldBeAJsonNumberValueArrayElement(0);
            elements[2].ShouldBeAJsonStringValueArrayElement("");
            elements[3].ShouldBeAJsonNullValueArrayElement();
            elements[4].ShouldBeAJsonObjectArrayElement();
            elements[5].ShouldBeAJsonArrayArrayElement();
        }
Ejemplo n.º 18
0
 public void should_set_field_null_value()
 {
     var element = new JElement(ElementType.Object);
     element.AddValueMember("field1", null);
     _encoder.Encode(element).ShouldEqual("{\"field1\":null}");
 }
Ejemplo n.º 19
0
 public void should_set_field_empty_object_value()
 {
     var element = new JElement(ElementType.Object);
     element.AddMember("field1", ElementType.Object);
     _encoder.Encode(element).ShouldEqual("{\"field1\":{}}");
 }
Ejemplo n.º 20
0
 public void should_set_field_array_value()
 {
     var element = new JElement(ElementType.Object);
     var array = element.AddMember("field1", ElementType.Array);
     array.AddArrayValueElement(1);
     array.AddArrayValueElement("hai");
     _encoder.Encode(element).ShouldEqual("{\"field1\":[1,\"hai\"]}");
 }
Ejemplo n.º 21
0
 private static JElement Load(XDocument document)
 {
     var jsonElement = new JElement(GetRootType(document.Root));
     Load(jsonElement, document.Root);
     return jsonElement;
 }
Ejemplo n.º 22
0
 public void should_save_with_whitespace()
 {
     var element = new JElement(ElementType.Object);
     element.AddValueMember("field1", "hai");
     _encoder.Encode(element, pretty: true).ShouldEqual("{\r\n  \"field1\": \"hai\"\r\n}");
 }
Ejemplo n.º 23
0
 public void should_set_multiple_fields()
 {
     var element = new JElement(ElementType.Object);
     element.AddValueMember("field1", "oh");
     element.AddValueMember("field2", "hai");
     _encoder.Encode(element).ShouldEqual("{\"field1\":\"oh\",\"field2\":\"hai\"}");
 }
Ejemplo n.º 24
0
 public void should_set_field_string_value()
 {
     var element = new JElement(ElementType.Object);
     element.AddValueMember("field1", "hai");
     element.AddValueMember("field2", 'y');
     _encoder.Encode(element).ShouldEqual("{\"field1\":\"hai\",\"field2\":\"y\"}");
 }
Ejemplo n.º 25
0
 public void should_set_array_number_elements()
 {
     var element = new JElement(ElementType.Array);
     element.Type = ElementType.Array;
     element.AddArrayValueElement((decimal)1.1);
     element.AddArrayValueElement((float)2.2);
     element.AddArrayValueElement((double)3.3);
     element.AddArrayValueElement((sbyte)4);
     element.AddArrayValueElement((byte)5);
     element.AddArrayValueElement((short)6);
     element.AddArrayValueElement((ushort)7);
     element.AddArrayValueElement((int)8);
     element.AddArrayValueElement((uint)9);
     element.AddArrayValueElement((long)10);
     element.AddArrayValueElement((ulong)11);
     _encoder.Encode(element).ShouldEqual("[1.1,2.2,3.3,4,5,6,7,8,9,10,11]");
 }
Ejemplo n.º 26
0
 public JsonNode(NodeType type, Options options)
 {
     _options = options;
     Element  = JElement.Create(type == NodeType.Array ? ElementType.Array : ElementType.Object);
 }
Ejemplo n.º 27
0
 private void Save(JElement jsonElement, XElement xmlElement)
 {
     SetElementType(xmlElement, jsonElement.Type);
     if (jsonElement.IsValue) SetElementValue(jsonElement, xmlElement);
     else jsonElement.ForEach(x => Save(x, CreateElement(jsonElement.IsArray, x, xmlElement)));
 }
Ejemplo n.º 28
0
 public void should_set_array_bool_element()
 {
     var element = new JElement(ElementType.Array);
     element.AddArrayValueElement(true);
     _encoder.Encode(element).ShouldEqual("[true]");
 }
Ejemplo n.º 29
0
 public JsonNode(Stream stream, Encoding encoding = null)
 {
     Element = Exception <JsonParseException>
               .Map(() => JElement.Load(stream, encoding), x => new ParseException(x, NodeFormat));
 }
Ejemplo n.º 30
0
 private static void Load(JElement jsonElement, XElement xmlElement)
 {
     if (jsonElement.IsValue) jsonElement.Value = ParseJsonValue(xmlElement, jsonElement.Type);
     else xmlElement.Elements().ForEach(x => Load(jsonElement.Type == ElementType.Array ? jsonElement.AddArrayElement(GetElementType(x)) :
         jsonElement.AddMember(GetName(x), GetElementType(x)), x));
 }
Ejemplo n.º 31
0
 public void should_set_field_number_values()
 {
     var element = new JElement(ElementType.Object);
     element.AddValueMember("field1", (decimal)1.1);
     element.AddValueMember("field2", (float)2.2);
     element.AddValueMember("field3", (double)3.3);
     element.AddValueMember("field4", (sbyte)4);
     element.AddValueMember("field5", (byte)5);
     element.AddValueMember("field6", (short)6);
     element.AddValueMember("field7", (ushort)7);
     element.AddValueMember("field8", (int)8);
     element.AddValueMember("field9", (uint)9);
     element.AddValueMember("field10", (long)10);
     element.AddValueMember("field11", (ulong)11);
     _encoder.Encode(element).ShouldEqual("{" +
         "\"field1\":1.1," +
         "\"field2\":2.2," +
         "\"field3\":3.3," +
         "\"field4\":4," +
         "\"field5\":5," +
         "\"field6\":6," +
         "\"field7\":7," +
         "\"field8\":8," +
         "\"field9\":9," +
         "\"field10\":10," +
         "\"field11\":11" +
         "}");
 }
Ejemplo n.º 32
0
 public void should_set_field_object_value()
 {
     var element = new JElement(ElementType.Object);
     var @object = element.AddMember("field1", ElementType.Object);
     @object.AddValueMember("field2", 1);
     @object.AddValueMember("field3", "hai");
     _encoder.Encode(element).ShouldEqual("{\"field1\":{\"field2\":1,\"field3\":\"hai\"}}");
 }
Ejemplo n.º 33
0
 public void should_set_array_object_element()
 {
     var element = new JElement(ElementType.Array);
     var @object = element.AddArrayElement(ElementType.Object);
     @object.AddValueMember("field2", 1);
     @object.AddValueMember("field3", "hai");
     _encoder.Encode(element).ShouldEqual("[{\"field2\":1,\"field3\":\"hai\"}]");
 }
Ejemplo n.º 34
0
 public void should_set_multiple_array_elements()
 {
     var element = new JElement(ElementType.Array);
     element.AddArrayValueElement("oh");
     element.AddArrayValueElement("hai");
     _encoder.Encode(element).ShouldEqual("[\"oh\",\"hai\"]");
 }
Ejemplo n.º 35
0
 public void should_set_array_string_elements()
 {
     var element = new JElement(ElementType.Array);
     element.Type = ElementType.Array;
     element.AddArrayValueElement("hai");
     element.AddArrayValueElement('y');
     _encoder.Encode(element).ShouldEqual("[\"hai\",\"y\"]");
 }
Ejemplo n.º 36
0
 public JsonNode(byte[] bytes, Encoding encoding = null)
 {
     Element = Exception <JsonParseException>
               .Map(() => JElement.Load(bytes, encoding), x => new ParseException(x, NodeFormat));
 }
Ejemplo n.º 37
0
 public JsonNode(string json)
 {
     Element = Exception <JsonParseException>
               .Map(() => JElement.Load(json), x => new ParseException(x, NodeFormat));
 }
Ejemplo n.º 38
0
 public void should_set_array_array_element()
 {
     var element = new JElement(ElementType.Array);
     var array = element.AddArrayElement(ElementType.Array);
     array.AddArrayValueElement(1);
     array.AddArrayValueElement("hai");
     _encoder.Encode(element).ShouldEqual("[[1,\"hai\"]]");
 }
Ejemplo n.º 39
0
        public void should_add_value_fields_with_explicit_values()
        {
            var element = new JElement(ElementType.Object);
            element.AddValueMember("field1", true);
            element.AddValueMember("field2", 5);
            element.AddValueMember("field3", "hai");
            element.AddValueMember("field4", null);

            element.Count().ShouldEqual(4);
            var fields = element.ToList();
            fields[0].ShouldBeAJsonBoolValueField("field1", true);
            fields[1].ShouldBeAJsonNumberValueField("field2", 5);
            fields[2].ShouldBeAJsonStringValueField("field3", "hai");
            fields[3].ShouldBeAJsonNullValueField("field4");
        }
Ejemplo n.º 40
0
 public void should_set_escaped_array_string_elements()
 {
     var element = new JElement(ElementType.Array);
     element.Type = ElementType.Array;
     element.AddArrayValueElement(DateTime.MaxValue.ToString());
     _encoder.Encode(element).ShouldEqual("[\"{0}\"]"
         .ToFormat(DateTime.MaxValue.ToString().Replace("/", "\\/")));
 }
Ejemplo n.º 41
0
 private JsonNode(JElement element, JsonNode parent) : base(parent)
 {
     Element = element;
 }
Ejemplo n.º 42
0
 public void should_set_array_empty_object_element()
 {
     var element = new JElement(ElementType.Array);
     element.AddArrayElement(ElementType.Object);
     _encoder.Encode(element).ShouldEqual("[{}]");
 }
Ejemplo n.º 43
0
 public void should_set_escaped_field_string_value()
 {
     var element = new JElement(ElementType.Object);
     element.AddValueMember("field1", DateTime.MaxValue.ToString());
     _encoder.Encode(element).ShouldEqual("{{\"field1\":\"{0}\"}}"
         .ToFormat(DateTime.MaxValue.ToString().Replace("/", "\\/")));
 }
Ejemplo n.º 44
0
 private void SetElementValue(JElement jsonElement, XElement xmlElement)
 {
     switch (jsonElement.Type)
     {
         case ElementType.Null: return;
         case ElementType.Boolean: xmlElement.Value = jsonElement.Value.ToString().ToLower(); break;
         case ElementType.String: xmlElement.Value = jsonElement.Value.ToString(); break;
         default: xmlElement.Value = SerializeGeneral(jsonElement.Value); break;
     }
 }
Ejemplo n.º 45
0
 public void should_set_array_null_element()
 {
     var element = new JElement(ElementType.Array);
     element.AddArrayValueElement(null);
     _encoder.Encode(element).ShouldEqual("[null]");
 }