- Fixed null ref errors on empty json/xml body
- Added PassIfNotFound option to XPathExtractionRule
Showing
6 changed files
with
76 additions
and
70 deletions
No preview for this file type
No preview for this file type
This diff is collapsed.
Click to expand it.
... | @@ -86,25 +86,28 @@ namespace WebTest.WebService.Plugin.ResultTab | ... | @@ -86,25 +86,28 @@ namespace WebTest.WebService.Plugin.ResultTab |
86 | { | 86 | { |
87 | try | 87 | try |
88 | { | 88 | { |
89 | this.dom = dom; | 89 | this.dom = dom; |
90 | XmlNode xNode = dom.DocumentElement; | 90 | if (dom.DocumentElement != null) |
91 | 91 | { | |
92 | // Load the XML into the TreeView. | 92 | XmlNode xNode = dom.DocumentElement; |
93 | treeView.Nodes.Clear(); | 93 | |
94 | 94 | // Load the XML into the TreeView. | |
95 | TreeNode treeNode = new TreeNode(xNode.Name); | 95 | treeView.Nodes.Clear(); |
96 | treeNode.Tag = xNode; | 96 | |
97 | if (xNode.HasChildNodes) | 97 | TreeNode treeNode = new TreeNode(xNode.Name); |
98 | { | 98 | treeNode.Tag = xNode; |
99 | treeNode.Nodes.Add(new TreeNode("dummy")); | 99 | if (xNode.HasChildNodes) |
100 | { | ||
101 | treeNode.Nodes.Add(new TreeNode("dummy")); | ||
102 | } | ||
103 | else | ||
104 | { | ||
105 | treeNode.Text = xNode.InnerXml.Trim(); | ||
106 | } | ||
107 | |||
108 | treeView.Nodes.Add(treeNode); | ||
109 | treeNode.Collapse(); | ||
100 | } | 110 | } |
101 | else | ||
102 | { | ||
103 | treeNode.Text = xNode.InnerXml.Trim(); | ||
104 | } | ||
105 | |||
106 | treeView.Nodes.Add(treeNode); | ||
107 | treeNode.Collapse(); | ||
108 | } | 111 | } |
109 | catch (Exception ex) | 112 | catch (Exception ex) |
110 | { | 113 | { | ... | ... |
... | @@ -50,7 +50,12 @@ namespace WebTest.WebService.Plugin.Runtime | ... | @@ -50,7 +50,12 @@ namespace WebTest.WebService.Plugin.Runtime |
50 | { | 50 | { |
51 | get { return randomMatch; } | 51 | get { return randomMatch; } |
52 | set { randomMatch = value; } | 52 | set { randomMatch = value; } |
53 | } | 53 | } |
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; } | ||
54 | 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. |
... | @@ -62,64 +67,62 @@ namespace WebTest.WebService.Plugin.Runtime | ... | @@ -62,64 +67,62 @@ 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 | { | 71 | if (contentHandler.IsBinary) |
67 | return; | 72 | { |
68 | } | 73 | contentHandler.MessageBytes = e.Response.BodyBytes; |
74 | } | ||
75 | else | ||
76 | { | ||
77 | contentHandler.MessageString = e.Response.BodyString; | ||
78 | } | ||
69 | 79 | ||
70 | if (contentHandler.IsBinary) | 80 | XPathNodeIterator iterator = contentHandler.EvaluateXPath(XPathToSearch); |
71 | { | ||
72 | contentHandler.MessageBytes = e.Response.BodyBytes; | ||
73 | } | ||
74 | else | ||
75 | { | ||
76 | contentHandler.MessageString = e.Response.BodyString; | ||
77 | } | ||
78 | 81 | ||
79 | XPathNodeIterator iterator = contentHandler.EvaluateXPath(XPathToSearch); | 82 | List<string> values = new List<string>(); |
80 | 83 | ||
81 | List<string> values = new List<string>(); | 84 | int i = 0; |
85 | while (iterator.MoveNext()) | ||
86 | { | ||
87 | XPathNavigator nav2 = iterator.Current.Clone(); | ||
82 | 88 | ||
83 | int i = 0; | 89 | string value; |
84 | while (iterator.MoveNext()) | 90 | if (nav2.NodeType.Equals(XPathNodeType.Element)) |
85 | { | 91 | { |
86 | XPathNavigator nav2 = iterator.Current.Clone(); | 92 | value = nav2.InnerXml; |
93 | } | ||
94 | else | ||
95 | { | ||
96 | value = nav2.Value; | ||
97 | } | ||
87 | 98 | ||
88 | string value; | 99 | values.Add(value); |
89 | if (nav2.NodeType.Equals(XPathNodeType.Element)) | 100 | if (!ExtractRandomMatch && (i == Index)) |
90 | { | 101 | { |
91 | value = nav2.InnerXml; | 102 | // add the extracted value to the Web test context |
92 | } | 103 | e.WebTest.Context.Add(this.ContextParameterName, value); |
93 | else | 104 | e.Success = true; |
94 | { | 105 | return; |
95 | value = nav2.Value; | 106 | } |
107 | i++; | ||
96 | } | 108 | } |
97 | 109 | ||
98 | values.Add(value); | 110 | if (ExtractRandomMatch && (values.Count > 0)) |
99 | if (!ExtractRandomMatch && (i == Index)) | ||
100 | { | 111 | { |
101 | // add the extracted value to the Web test context | 112 | Random random = new Random(); |
102 | e.WebTest.Context.Add(this.ContextParameterName, value); | 113 | e.WebTest.Context.Add(this.ContextParameterName, values[random.Next(values.Count)]); |
103 | e.Success = true; | 114 | e.Success = true; |
104 | return; | 115 | return; |
105 | } | 116 | } |
106 | i++; | ||
107 | } | ||
108 | |||
109 | if (ExtractRandomMatch && (values.Count > 0)) | ||
110 | { | ||
111 | Random random = new Random(); | ||
112 | e.WebTest.Context.Add(this.ContextParameterName, values[random.Next(values.Count)]); | ||
113 | e.Success = true; | ||
114 | return; | ||
115 | } | 117 | } |
116 | } | 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 | } | ... | ... |
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> | 2 | <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> |
3 | 3 | ||
4 | <Product Id="{289E27D1-0F89-4F1A-A2C7-9584091B9950}" Name="Web Test Plugin for Web Service Messages - VS 2012" Language="1033" Version="3.0.0.0" Manufacturer="Microsoft IT" UpgradeCode="{BF388820-5266-41AF-BFFE-DC183C37D624}"> | 4 | <Product Id="{382AA10B-843C-474A-B662-C051AD2B160B}" Name="Web Test Plugin for Web Service Messages - VS 2013" Language="1033" Version="3.3.0.0" Manufacturer="LIGHTS IN LINE AB" UpgradeCode="{BF388820-5266-41AF-BFFE-DC183C37D624}"> |
5 | <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> | 5 | <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> |
6 | <Media Id="1" Cabinet="WebServicePlugins1.cab" EmbedCab="yes" /> | 6 | <Media Id="1" Cabinet="WebServicePlugins1.cab" EmbedCab="yes" /> |
7 | 7 | ||
8 | <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> | 8 | <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of [ProductName] is already installed." /> |
9 | 9 | ||
10 | <Feature Id="ProductFeature" Title="Web Test Plugin for Web Service Messages" Level="1"> | 10 | <Feature Id="ProductFeature" Title="Web Test Plugin for Web Service Messages" Level="1"> |
11 | <ComponentRef Id="WebTestMessageEditor" /> | 11 | <ComponentRef Id="WebTestMessageEditor" /> |
... | @@ -13,19 +13,19 @@ | ... | @@ -13,19 +13,19 @@ |
13 | <ComponentRef Id="WebTestRuntime" /> | 13 | <ComponentRef Id="WebTestRuntime" /> |
14 | </Feature> | 14 | </Feature> |
15 | 15 | ||
16 | <Property Id="VS2012INSTALLFOLDER" Secure="yes"> | 16 | <Property Id="VS2013INSTALLFOLDER" Secure="yes"> |
17 | <RegistrySearch Id="VS2012InstallationFolderRegistrySearchId" Type="raw" | 17 | <RegistrySearch Id="VS2013InstallationFolderRegistrySearchId" Type="raw" |
18 | Root="HKLM" Key="SOFTWARE\Microsoft\VisualStudio\11.0" Name="InstallDir"></RegistrySearch> | 18 | Root="HKLM" Key="SOFTWARE\Microsoft\VisualStudio\12.0" Name="InstallDir"></RegistrySearch> |
19 | </Property> | 19 | </Property> |
20 | 20 | ||
21 | <Condition Message="Visual Studio 2012 not found."> | 21 | <Condition Message="Visual Studio 2013 not found."> |
22 | Installed OR VS2012INSTALLFOLDER | 22 | Installed OR VS2013INSTALLFOLDER |
23 | </Condition> | 23 | </Condition> |
24 | </Product> | 24 | </Product> |
25 | 25 | ||
26 | <Fragment> | 26 | <Fragment> |
27 | <Directory Id="TARGETDIR" Name="SourceDir"> | 27 | <Directory Id="TARGETDIR" Name="SourceDir"> |
28 | <Directory Id="VS2012INSTALLFOLDER"> | 28 | <Directory Id="VS2013INSTALLFOLDER"> |
29 | <Directory Id="PrivateAssemblies" Name="PrivateAssemblies"> | 29 | <Directory Id="PrivateAssemblies" Name="PrivateAssemblies"> |
30 | <Directory Id="WebTestPlugins" Name="WebTestPlugins"> | 30 | <Directory Id="WebTestPlugins" Name="WebTestPlugins"> |
31 | <Component Id="WebTestMessageEditor" Guid="{17E95CD2-6B83-46C9-AEE5-019853FF62EC}"> | 31 | <Component Id="WebTestMessageEditor" Guid="{17E95CD2-6B83-46C9-AEE5-019853FF62EC}"> |
... | @@ -43,7 +43,7 @@ | ... | @@ -43,7 +43,7 @@ |
43 | <Directory Id="AppDataFolder"> | 43 | <Directory Id="AppDataFolder"> |
44 | <Directory Id="MSAppDataDir" Name="Microsoft"> | 44 | <Directory Id="MSAppDataDir" Name="Microsoft"> |
45 | <Directory Id="VSAppDataDir" Name="VisualStudio"> | 45 | <Directory Id="VSAppDataDir" Name="VisualStudio"> |
46 | <Directory Id="VSAppDataVersionDir" Name="11.0"> | 46 | <Directory Id="VSAppDataVersionDir" Name="12.0"> |
47 | <Directory Id="VSAddins" Name="Addins"> | 47 | <Directory Id="VSAddins" Name="Addins"> |
48 | <Component Id="WebTestResultTab" Guid="{27569640-6946-4E4F-8E55-109E99A79DB9}"> | 48 | <Component Id="WebTestResultTab" Guid="{27569640-6946-4E4F-8E55-109E99A79DB9}"> |
49 | <RegistryValue KeyPath="yes" Root="HKCU" Key="SOFTWARE\Microsoft\WebServicePlugin" Name="Installed" Type="integer" Value="1" Action="write" /> | 49 | <RegistryValue KeyPath="yes" Root="HKCU" Key="SOFTWARE\Microsoft\WebServicePlugin" Name="Installed" Type="integer" Value="1" Action="write" /> | ... | ... |
-
Please register or sign in to post a comment