New Requst Plugin
- ExtractRegularExpressionFromResources Will add regular expression extranction rule to dependent (dynamic and static) requests.
Showing
1 changed file
with
72 additions
and
0 deletions
| ... | @@ -433,6 +433,78 @@ namespace LIL_VSTT_Plugins | ... | @@ -433,6 +433,78 @@ namespace LIL_VSTT_Plugins |
| 433 | } | 433 | } |
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | [DisplayName("Extract Regular Expression From Dependents"), Description("Extracts data matching a regular expression from dependents belonging to this request")] | ||
| 437 | public class ExtractRegularExpressionFromResources : WebTestRequestPlugin | ||
| 438 | { | ||
| 439 | [DisplayName("Match Dependents"), Description("If specified, this regular expression must match the dependent. If empty, the extraction rule will be applied to all dependents.")] | ||
| 440 | public String DepRegex { get; set; } | ||
| 441 | |||
| 442 | [DisplayName("Context Parameter Name"), Description("Parameter name for the Extraction Rule")] | ||
| 443 | [Category("Extract Regular Expression Rule")] | ||
| 444 | public String ContextParameterName { get; set; } | ||
| 445 | |||
| 446 | [DisplayName("Regular Expression"), Description("Regular Expression for the Extraction rule")] | ||
| 447 | [Category("Extract Regular Expression Rule")] | ||
| 448 | public String RegularExpression { get; set; } | ||
| 449 | |||
| 450 | [DisplayName("Ignore Case"), Description("Ignore Case for the Extraction rule")] | ||
| 451 | [Category("Extract Regular Expression Rule")] | ||
| 452 | [DefaultValue(false)] | ||
| 453 | public bool IgnoreCase { get; set; } | ||
| 454 | |||
| 455 | [DisplayName("Required"), Description("Required for the Extraction rule")] | ||
| 456 | [Category("Extract Regular Expression Rule")] | ||
| 457 | [DefaultValue(true)] | ||
| 458 | public bool Required { get; set; } | ||
| 459 | |||
| 460 | [DisplayName("Index"), Description("Index for the Extraction rule")] | ||
| 461 | [Category("Extract Regular Expression Rule")] | ||
| 462 | [DefaultValue(0)] | ||
| 463 | public int Index { get; set; } | ||
| 464 | |||
| 465 | [DisplayName("Html Decode"), Description("Html Decode for the Extraction rule")] | ||
| 466 | [Category("Extract Regular Expression Rule")] | ||
| 467 | [DefaultValue(true)] | ||
| 468 | public bool HtmlDecode { get; set; } | ||
| 469 | |||
| 470 | [DisplayName("Use Groups"), Description("Use Groups for the Extraction rule")] | ||
| 471 | [Category("Extract Regular Expression Rule")] | ||
| 472 | [DefaultValue(false)] | ||
| 473 | public bool UseGroups { get; set; } | ||
| 474 | |||
| 475 | public override void PostRequest(object sender, PostRequestEventArgs e) | ||
| 476 | { | ||
| 477 | base.PostRequest(sender, e); | ||
| 478 | Regex rx = null; | ||
| 479 | if(!String.IsNullOrEmpty(DepRegex)) | ||
| 480 | { | ||
| 481 | rx = new Regex(DepRegex); | ||
| 482 | } | ||
| 483 | e.WebTest.ResponseBodyCaptureLimit = 10000000; | ||
| 484 | if (e.Request.HasDependentRequests) | ||
| 485 | { | ||
| 486 | foreach (WebTestRequest r in e.Request.DependentRequests) | ||
| 487 | { | ||
| 488 | if (rx != null && rx.IsMatch(r.Url)) | ||
| 489 | { | ||
| 490 | ExtractionRuleReference ef = new ExtractionRuleReference(typeof(ExtractRegularExpression)); | ||
| 491 | ef.ContextParameterName = ContextParameterName; | ||
| 492 | ef.DisplayName = "AutoExtractDisplayName"; | ||
| 493 | ef.Description = "AutoExtractDescription"; | ||
| 494 | ef.ExecutionOrder = RuleExecutionOrder.BeforeDependents; | ||
| 495 | ef.Properties.Add("RegularExpression", RegularExpression); | ||
| 496 | ef.Properties.Add("IgnoreCase", IgnoreCase.ToString()); | ||
| 497 | ef.Properties.Add("Required", Required.ToString()); | ||
| 498 | ef.Properties.Add("Index", Index.ToString()); | ||
| 499 | ef.Properties.Add("HtmlDecode", HtmlDecode.ToString()); | ||
| 500 | ef.Properties.Add("UseGroups", UseGroups.ToString()); | ||
| 501 | r.ExtractionRuleReferences.Add(ef); | ||
| 502 | } | ||
| 503 | } | ||
| 504 | } | ||
| 505 | } | ||
| 506 | } | ||
| 507 | |||
| 436 | [DisplayName("Regular Expression Loop"), Description("Loop Condition that matches once on each regexp in previous response body")] | 508 | [DisplayName("Regular Expression Loop"), Description("Loop Condition that matches once on each regexp in previous response body")] |
| 437 | public class RegExpLoop : ConditionalRule | 509 | public class RegExpLoop : ConditionalRule |
| 438 | { | 510 | { | ... | ... |
-
Please register or sign in to post a comment