Commit 37321658 37321658e8f68fecc605c1719d7955fc4811dcc0 by Christian Gerdes

- Fixed null ref errors on empty json/xml body

- Added PassIfNotFound to XPathExtractionRule
1 parent 34618ddb
...@@ -87,6 +87,8 @@ namespace WebTest.WebService.Plugin.ResultTab ...@@ -87,6 +87,8 @@ namespace WebTest.WebService.Plugin.ResultTab
87 try 87 try
88 { 88 {
89 this.dom = dom; 89 this.dom = dom;
90 if (dom.DocumentElement != null)
91 {
90 XmlNode xNode = dom.DocumentElement; 92 XmlNode xNode = dom.DocumentElement;
91 93
92 // Load the XML into the TreeView. 94 // Load the XML into the TreeView.
...@@ -106,6 +108,7 @@ namespace WebTest.WebService.Plugin.ResultTab ...@@ -106,6 +108,7 @@ namespace WebTest.WebService.Plugin.ResultTab
106 treeView.Nodes.Add(treeNode); 108 treeView.Nodes.Add(treeNode);
107 treeNode.Collapse(); 109 treeNode.Collapse();
108 } 110 }
111 }
109 catch (Exception ex) 112 catch (Exception ex)
110 { 113 {
111 MessageBox.Show(ex.Message, "Error"); 114 MessageBox.Show(ex.Message, "Error");
......
...@@ -52,6 +52,11 @@ namespace WebTest.WebService.Plugin.Runtime ...@@ -52,6 +52,11 @@ namespace WebTest.WebService.Plugin.Runtime
52 set { randomMatch = value; } 52 set { randomMatch = value; }
53 } 53 }
54 54
55 [DisplayName("Pass if not found")]
56 [Description("If set to true, this rule will pass the request even if no match is found.")]
57 [DefaultValue(false)]
58 public bool passIfNotFound { get; set; }
59
55 /// <summary> 60 /// <summary>
56 /// The Extract method. The parameter e contains the Web test context. 61 /// The Extract method. The parameter e contains the Web test context.
57 /// </summary> 62 /// </summary>
...@@ -62,11 +67,7 @@ namespace WebTest.WebService.Plugin.Runtime ...@@ -62,11 +67,7 @@ namespace WebTest.WebService.Plugin.Runtime
62 try 67 try
63 { 68 {
64 ContentHandler contentHandler = ContentHandlerFactory.GetHandler(e.Response.ContentType); 69 ContentHandler contentHandler = ContentHandlerFactory.GetHandler(e.Response.ContentType);
65 if (contentHandler == null) 70 if (contentHandler != null) {
66 {
67 return;
68 }
69
70 if (contentHandler.IsBinary) 71 if (contentHandler.IsBinary)
71 { 72 {
72 contentHandler.MessageBytes = e.Response.BodyBytes; 73 contentHandler.MessageBytes = e.Response.BodyBytes;
...@@ -114,12 +115,14 @@ namespace WebTest.WebService.Plugin.Runtime ...@@ -114,12 +115,14 @@ namespace WebTest.WebService.Plugin.Runtime
114 return; 115 return;
115 } 116 }
116 } 117 }
118 }
117 catch (Exception ex) 119 catch (Exception ex)
118 { 120 {
119 e.Message = ex.Message; 121 e.Message = ex.Message;
120 } 122 }
121 123
122 e.Success = false; 124 e.Success = passIfNotFound;
125 e.Message += " (XPath not found)";
123 return; 126 return;
124 } 127 }
125 } 128 }
......