在groovy中读取XLSX数据,并在soapui免费工具中将值传递给soapui请求

时间:2018-02-16 12:42:45

标签: soapui

场景是我在XLSX文件中有很多行和列,我想读取数据并在单元格中获取数据以将这些值传递给soapUI请求

1 个答案:

答案 0 :(得分:1)

您可以使用简单的java excel连接代码来复制它。请按照以下代码: -

    class Program
    {
        static void Main(string[] args)
        {
            var x = new Dictionary<SomeClass, List<AnotherClass>>();
            var y = new Dictionary<SomeClass, List<AnotherClass>>();

            x.Add(new SomeClass { SomeNumericProperty = 1 }, new List<AnotherClass> { new AnotherClass { SomeStringProperty = "1" } });
            y.Add(new SomeClass { SomeNumericProperty = 1 }, new List<AnotherClass> { new AnotherClass { SomeStringProperty = "1" } });

            var w = new MyCustomComparer();
            var z = w.Equals(x, y);
        }
    }

    public class MyCustomComparer : IEqualityComparer<Dictionary<SomeClass, List<AnotherClass>>>
    {
        public bool Equals(Dictionary<SomeClass, List<AnotherClass>> x, Dictionary<SomeClass, List<AnotherClass>> y)
        {
            var keysAreEqual = x.Keys.OrderBy(o => o.GetHashCode()).SequenceEqual(y.Keys.OrderBy(o => o.GetHashCode()));
            var valuesAreEqual = x.SelectMany(o => o.Value).OrderBy(o => o.GetHashCode()).SequenceEqual(y.SelectMany(o => o.Value).OrderBy(o => o.GetHashCode()));

            return keysAreEqual && valuesAreEqual;
        }

        public int GetHashCode(Dictionary<SomeClass, List<AnotherClass>> obj)
        {
            throw new NotImplementedException();
        }
    }

    public class AnotherClass
    {
        protected bool Equals(AnotherClass other)
        {
            return string.Equals(SomeStringProperty, other.SomeStringProperty);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            if (obj.GetType() != this.GetType())
            {
                return false;
            }

            return Equals((AnotherClass)obj);
        }

        public override int GetHashCode()
        {
            int hash = 13;
            hash = (hash * 7) + SomeStringProperty.GetHashCode();
            return hash;
        }

        public string SomeStringProperty { get; set; }
    }

    public class SomeClass
    {
        public int SomeNumericProperty { get; set; }

        protected bool Equals(SomeClass other)
        {
            return SomeNumericProperty == other.SomeNumericProperty;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            if (obj.GetType() != this.GetType())
            {
                return false;
            }

            return Equals((SomeClass)obj);
        }

        public override int GetHashCode()
        {
            int hash = 13;
            hash = (hash * 7) + SomeNumericProperty.GetHashCode();
            return hash;
        }
    }

之后使用基本的java代码来读取列并使用Iterator遍历它。完成后,获取要在请求中传递的所需数据并将其放入属性testStep中,然后使用内置的GetData方法进入soapui请求并参数化所有数据。