예제 #1
0
        public JMeterOutputFileParser(string filePath)
        {
            if (System.IO.File.Exists(filePath))
            {
                this._filePath = filePath;
                _doc = XDocument.Parse(this.PreProcessXml(System.IO.File.ReadAllText(filePath)));
                var httpSampleNodes = _doc.Descendants().ToList();
                foreach (var node in httpSampleNodes)
                {
                    if (node.Name == "httpSample" || node.Name == "sample")
                    {
                        var responseHeader = node.Element("responseHeader").Value;
                        var requestHeader = node.Element("requestHeader").Value;
                        var responseData = node.Element("responseData").Value;
                        var queryString = node.Element("queryString") == null ? string.Empty : node.Element("queryString").Value;
                        // Does 't' mean the response time?
                        var responseTime = node.Attribute("t").Value;
                        var cgiName = node.Attribute("lb").Value;
                        var returnCode = node.Attribute("rc").Value;
                        var cookies = node.Element("cookies") == null ? string.Empty : node.Element("cookies").Value;
                        var url = node.Element("java.net.URL") == null ? string.Empty : node.Element("java.net.URL").Value;
                        var method = node.Element("method") == null ? string.Empty : node.Element("method").Value;
                        var threadName = node.Attribute("tn").Value;
                        AssertionResult assertionResult = null;
                        var assertionNode = node.Element("assertionResult");
                        if (assertionNode != null)
                        {
                            assertionResult = new AssertionResult();
                            assertionResult.Error = assertionNode.Element("error").Value;
                            assertionResult.Failure = assertionNode.Element("failure").Value.ToLower();
                            if (assertionNode.Element("failureMessage") != null && assertionNode.Element("failure").Value.ToLower() == "true")
                            {
                                var failsureMsg = assertionNode.Element("failureMessage").Value;
                                //if (failsureMsg.ToLower() == "false" || string.IsNullOrEmpty(failsureMsg))
                                {
                                    assertionResult.FailureMsg = failsureMsg;
                                }
                            }
                            assertionResult.Name = assertionNode.Element("name").Value;
                        }
                        var httpSample = new HttpSample();
                        httpSample.AssertionResult = assertionResult;
                        httpSample.CGIName = cgiName;
                        httpSample.Cookies = cookies;
                        httpSample.Method = method;
                        httpSample.QueryString = queryString;
                        httpSample.RequestHeader = requestHeader;
                        httpSample.ResponseData = responseData;
                        httpSample.ResponseHeader = responseHeader;
                        httpSample.ResponseTime = responseTime;
                        httpSample.ReturnCode = returnCode;
                        httpSample.ThreadName = threadName;
                        httpSample.Url = url;
                        // Find parent httpsample, if it has parent httpsample node, set parent's lb attribute to it's parent CGI Name
                        if (node.Parent.Name == "sample")
                        {
                            httpSample.ParentCGIName = node.Parent.Attribute("lb").Value;
                        }
                        else if (node.Parent.Name == "httpSample")
                        {
                            httpSample.ParentCGIName = node.Parent.Attribute("lb").Value;
                        }
                        if (httpSample.CGIName != "忽略")
                        {
                            _httpSamples.Add(httpSample);
                        }
                    }
                }

            }
        }
예제 #2
0
 public JMeterOutputFileParser(string filePath)
 {
     if (System.IO.File.Exists(filePath))
     {
         this._filePath = filePath;
         _doc           = XDocument.Parse(this.PreProcessXml(System.IO.File.ReadAllText(filePath)));
         var httpSampleNodes = _doc.Descendants().ToList();
         foreach (var node in httpSampleNodes)
         {
             if (node.Name == "httpSample" || node.Name == "sample")
             {
                 var responseHeader = node.Element("responseHeader").Value;
                 var requestHeader  = node.Element("requestHeader").Value;
                 var responseData   = node.Element("responseData").Value;
                 var queryString    = node.Element("queryString") == null ? string.Empty : node.Element("queryString").Value;
                 // Does 't' mean the response time?
                 var             responseTime    = node.Attribute("t").Value;
                 var             cgiName         = node.Attribute("lb").Value;
                 var             returnCode      = node.Attribute("rc").Value;
                 var             cookies         = node.Element("cookies") == null ? string.Empty : node.Element("cookies").Value;
                 var             url             = node.Element("java.net.URL") == null ? string.Empty : node.Element("java.net.URL").Value;
                 var             method          = node.Element("method") == null ? string.Empty : node.Element("method").Value;
                 var             threadName      = node.Attribute("tn").Value;
                 AssertionResult assertionResult = null;
                 var             assertionNode   = node.Element("assertionResult");
                 if (assertionNode != null)
                 {
                     assertionResult         = new AssertionResult();
                     assertionResult.Error   = assertionNode.Element("error").Value;
                     assertionResult.Failure = assertionNode.Element("failure").Value.ToLower();
                     if (assertionNode.Element("failureMessage") != null && assertionNode.Element("failure").Value.ToLower() == "true")
                     {
                         var failsureMsg = assertionNode.Element("failureMessage").Value;
                         //if (failsureMsg.ToLower() == "false" || string.IsNullOrEmpty(failsureMsg))
                         {
                             assertionResult.FailureMsg = failsureMsg;
                         }
                     }
                     assertionResult.Name = assertionNode.Element("name").Value;
                 }
                 var httpSample = new HttpSample();
                 httpSample.AssertionResult = assertionResult;
                 httpSample.CGIName         = cgiName;
                 httpSample.Cookies         = cookies;
                 httpSample.Method          = method;
                 httpSample.QueryString     = queryString;
                 httpSample.RequestHeader   = requestHeader;
                 httpSample.ResponseData    = responseData;
                 httpSample.ResponseHeader  = responseHeader;
                 httpSample.ResponseTime    = responseTime;
                 httpSample.ReturnCode      = returnCode;
                 httpSample.ThreadName      = threadName;
                 httpSample.Url             = url;
                 // Find parent httpsample, if it has parent httpsample node, set parent's lb attribute to it's parent CGI Name
                 if (node.Parent.Name == "sample")
                 {
                     httpSample.ParentCGIName = node.Parent.Attribute("lb").Value;
                 }
                 else if (node.Parent.Name == "httpSample")
                 {
                     httpSample.ParentCGIName = node.Parent.Attribute("lb").Value;
                 }
                 if (httpSample.CGIName != "忽略")
                 {
                     _httpSamples.Add(httpSample);
                 }
             }
         }
     }
 }