0

I'm using Visual Studio 2015 Web Performance test (.webtest) and have an Extraction Rule in place to capture a 8-digit number that references a check number (via inner text) into a context parameter.

If the number only contains 6-digits, then it has two blank spaces in front of the check number. This causes an issue because I'm using the check number in a form parameter and those blank spaces need to be switch to zeroes (0).

My question is what's the best way to handle the comparison? Is there a way to edit the context parameter (named "CheckNBR"), or can I overwrite the Extraction Rule to manipulate the parameter? Maybe create a custom Extraction Rule instead? I'm kinda going in all directions on this and not sure what options work the best.

[Update] Instead of determining the best way, I'm re-directing the question towards the editing of the context parameter. Once I set the parameter from the Extraction rule, how can I edit it?

4

1 回答 1

0

有几种可能的方法。

您可以编写一个自定义提取规则来查找所需的文本,根据需要对其进行修改,然后将其保存到上下文变量中。这可能是最复杂的版本。

您可以编写使用内置提取规则的自定义提取规则,然后修改结果。基于以下(未测试,未编译)的代码应该可以工作。当然,您需要编写自己的ModifyTheTextAsNeeded. 然后更改 web 测试以使用下面的提取而不是原始的。

public class ExtractAndModifyHtmlTagInnerText : ExtractHtmlTagInnerText
{
    public override void Extract(object sender, ExtractionEventArgs e)
    {
        base.Extract(sender, e);

        string extractedText = e.WebTest.Context[this.ContextParameterName].ToString();
        string modifiedText = ModifyTheTextAsNeeded(extractedText);
        e.WebTest.Context[this.ContextParameterName] = modifiedText
    }
}

另一种方法是将类似于上面显示的方法主体的最后三行的内容放入插件中。它可能是PreRequest在具有提取规则的请求之后的下一个请求中使用的插件。

于 2017-02-07T10:30:29.413 回答