解决方案是按照此处Custom Extraction Rule
的说明创建一个,并使用正则表达式来解析两次 html 正文
提取方法:
public override void Extract(object sender, ExtractionEventArgs e)
{
var val1 = GetInputValueByName(e.Response.BodyString, "Secret");
var val2 = GetInputValueByName(e.Response.BodyString, $"Field[{val1}].value");
if (!string.IsNullOrEmpty(val2 ))
{
e.Success = true;
e.WebTest.Context.Add(this.ContextParameterName, val2);
}
else
{
// If the extraction fails, set the error text that the user sees
e.Success = false;
e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found: {0}", Name);
}
}
private string GetInputValueByName(string html, string name)
{
Match match = Regex.Match(html, "<input[^>]*name=\"" + Regex.Escape(name) + "\"[^>]*value=\"([^\"]*)\"");
if (match.Success)
{
return match.Groups[1].Value;
}
return string.Empty;
}