Commit 35418d67 35418d674e1b245caf365b1bab4c525acf549e27 by Christian Gerdes

New Requst Plugin

- ExtractRegularExpressionFromResources
Will add regular expression extranction rule to dependent (dynamic and static) requests.
1 parent baddbbf1
......@@ -433,6 +433,78 @@ namespace LIL_VSTT_Plugins
}
}
[DisplayName("Extract Regular Expression From Dependents"), Description("Extracts data matching a regular expression from dependents belonging to this request")]
public class ExtractRegularExpressionFromResources : WebTestRequestPlugin
{
[DisplayName("Match Dependents"), Description("If specified, this regular expression must match the dependent. If empty, the extraction rule will be applied to all dependents.")]
public String DepRegex { get; set; }
[DisplayName("Context Parameter Name"), Description("Parameter name for the Extraction Rule")]
[Category("Extract Regular Expression Rule")]
public String ContextParameterName { get; set; }
[DisplayName("Regular Expression"), Description("Regular Expression for the Extraction rule")]
[Category("Extract Regular Expression Rule")]
public String RegularExpression { get; set; }
[DisplayName("Ignore Case"), Description("Ignore Case for the Extraction rule")]
[Category("Extract Regular Expression Rule")]
[DefaultValue(false)]
public bool IgnoreCase { get; set; }
[DisplayName("Required"), Description("Required for the Extraction rule")]
[Category("Extract Regular Expression Rule")]
[DefaultValue(true)]
public bool Required { get; set; }
[DisplayName("Index"), Description("Index for the Extraction rule")]
[Category("Extract Regular Expression Rule")]
[DefaultValue(0)]
public int Index { get; set; }
[DisplayName("Html Decode"), Description("Html Decode for the Extraction rule")]
[Category("Extract Regular Expression Rule")]
[DefaultValue(true)]
public bool HtmlDecode { get; set; }
[DisplayName("Use Groups"), Description("Use Groups for the Extraction rule")]
[Category("Extract Regular Expression Rule")]
[DefaultValue(false)]
public bool UseGroups { get; set; }
public override void PostRequest(object sender, PostRequestEventArgs e)
{
base.PostRequest(sender, e);
Regex rx = null;
if(!String.IsNullOrEmpty(DepRegex))
{
rx = new Regex(DepRegex);
}
e.WebTest.ResponseBodyCaptureLimit = 10000000;
if (e.Request.HasDependentRequests)
{
foreach (WebTestRequest r in e.Request.DependentRequests)
{
if (rx != null && rx.IsMatch(r.Url))
{
ExtractionRuleReference ef = new ExtractionRuleReference(typeof(ExtractRegularExpression));
ef.ContextParameterName = ContextParameterName;
ef.DisplayName = "AutoExtractDisplayName";
ef.Description = "AutoExtractDescription";
ef.ExecutionOrder = RuleExecutionOrder.BeforeDependents;
ef.Properties.Add("RegularExpression", RegularExpression);
ef.Properties.Add("IgnoreCase", IgnoreCase.ToString());
ef.Properties.Add("Required", Required.ToString());
ef.Properties.Add("Index", Index.ToString());
ef.Properties.Add("HtmlDecode", HtmlDecode.ToString());
ef.Properties.Add("UseGroups", UseGroups.ToString());
r.ExtractionRuleReferences.Add(ef);
}
}
}
}
}
[DisplayName("Regular Expression Loop"), Description("Loop Condition that matches once on each regexp in previous response body")]
public class RegExpLoop : ConditionalRule
{
......