Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Christian Gerdes
/
WebServicePlugins
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
12
Merge Requests
0
Wiki
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
a23627ef
...
a23627efb95d75e498cb0ef579b1c67320e73176
authored
2018-02-08 17:23:28 +0100
by
Christian Gerdes
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added PassIfNotFound to XPathExtractionRule
1 parent
1f4f69a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
40 deletions
WebTestWebServiceRuntime/XPathExtractionRule.cs
WebTestWebServiceRuntime/XPathExtractionRule.cs
View file @
a23627e
...
...
@@ -52,6 +52,11 @@ namespace WebTest.WebService.Plugin.Runtime
set
{
randomMatch
=
value
;
}
}
[
DisplayName
(
"Pass if not found"
)]
[
Description
(
"If set to true, this rule will pass the request even if no match is found."
)]
[
DefaultValue
(
false
)]
public
bool
passIfNotFound
{
get
;
set
;
}
/// <summary>
/// The Extract method. The parameter e contains the Web test context.
/// </summary>
...
...
@@ -62,56 +67,53 @@ namespace WebTest.WebService.Plugin.Runtime
try
{
ContentHandler
contentHandler
=
ContentHandlerFactory
.
GetHandler
(
e
.
Response
.
ContentType
);
if
(
contentHandler
==
null
)
{
return
;
}
if
(
contentHandler
!=
null
)
{
if
(
contentHandler
.
IsBinary
)
{
contentHandler
.
MessageBytes
=
e
.
Response
.
BodyBytes
;
}
else
{
contentHandler
.
MessageString
=
e
.
Response
.
BodyString
;
}
if
(
contentHandler
.
IsBinary
)
{
contentHandler
.
MessageBytes
=
e
.
Response
.
BodyBytes
;
}
else
{
contentHandler
.
MessageString
=
e
.
Response
.
BodyString
;
}
XPathNodeIterator
iterator
=
contentHandler
.
EvaluateXPath
(
XPathToSearch
);
XPathNodeIterator
iterator
=
contentHandler
.
EvaluateXPath
(
XPathToSearch
);
List
<
string
>
values
=
new
List
<
string
>(
);
List
<
string
>
values
=
new
List
<
string
>();
int
i
=
0
;
while
(
iterator
.
MoveNext
())
{
XPathNavigator
nav2
=
iterator
.
Current
.
Clone
();
int
i
=
0
;
while
(
iterator
.
MoveNext
())
{
XPathNavigator
nav2
=
iterator
.
Current
.
Clone
();
string
value
;
if
(
nav2
.
NodeType
.
Equals
(
XPathNodeType
.
Element
))
{
value
=
nav2
.
InnerXml
;
}
else
{
value
=
nav2
.
Value
;
}
string
value
;
if
(
nav2
.
NodeType
.
Equals
(
XPathNodeType
.
Element
))
{
value
=
nav2
.
InnerXml
;
}
else
{
value
=
nav2
.
Value
;
values
.
Add
(
value
);
if
(!
ExtractRandomMatch
&&
(
i
==
Index
))
{
// add the extracted value to the Web test context
e
.
WebTest
.
Context
.
Add
(
this
.
ContextParameterName
,
value
);
e
.
Success
=
true
;
return
;
}
i
++;
}
values
.
Add
(
value
);
if
(!
ExtractRandomMatch
&&
(
i
==
Index
))
if
(
ExtractRandomMatch
&&
(
values
.
Count
>
0
))
{
// add the extracted value to the Web test context
e
.
WebTest
.
Context
.
Add
(
this
.
ContextParameterName
,
value
);
Random
random
=
new
Random
();
e
.
WebTest
.
Context
.
Add
(
this
.
ContextParameterName
,
value
s
[
random
.
Next
(
values
.
Count
)]
);
e
.
Success
=
true
;
return
;
}
i
++;
}
if
(
ExtractRandomMatch
&&
(
values
.
Count
>
0
))
{
Random
random
=
new
Random
();
e
.
WebTest
.
Context
.
Add
(
this
.
ContextParameterName
,
values
[
random
.
Next
(
values
.
Count
)]);
e
.
Success
=
true
;
return
;
}
}
catch
(
Exception
ex
)
...
...
@@ -119,7 +121,8 @@ namespace WebTest.WebService.Plugin.Runtime
e
.
Message
=
ex
.
Message
;
}
e
.
Success
=
false
;
e
.
Success
=
passIfNotFound
;
e
.
Message
+=
" (XPath not found)"
;
return
;
}
}
...
...
Please
register
or
sign in
to post a comment