Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ExtractText.ExtractRandomMatch Property

 

Indicates whether the extracted value is chosen randomly from all matches in the HtmlDocument.

Namespace:   Microsoft.VisualStudio.TestTools.WebTesting.Rules
Assembly:  Microsoft.VisualStudio.QualityTools.WebTestFramework (in Microsoft.VisualStudio.QualityTools.WebTestFramework.dll)

[DefaultValueAttribute(false)]
public bool ExtractRandomMatch { get; set; }

Property Value

Type: System.Boolean

A Boolean value that indicates whether the extracted value is chosen randomly from all matches in the HtmlDocument.

Set this property to rue if you want a value to be randomly chosen from all the matches in the XML document. Set the property when you create the extraction rule. Then, the Web performance test run-time engine calls Extract() after the HTML response to the WebTestRequest has been received. The value of the ExtractRandomMatch property is not changed when Extract() is called.

The ExtractRandomMatch property would typically be set in a coded Web performance test in the GetRequestEnumerator after the ExtractText extraction rule has been created, and before the WebTestRequest has been returned.

Legacy Code Example

The following example shows a coded Web performance test whose code was produced through code generation. The code was not modified manually after it was generated. The ExtractRandomMatch property is set when the statement yield return Request1; is executed.

namespace TestProject1
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.VisualStudio.TestTools.WebTesting;
    using Microsoft.VisualStudio.TestTools.WebTesting.Rules;


    public class ExtractRandomExampleCoded : WebTest
    {

        public ExtractRandomExampleCoded()
        {
            this.PreAuthenticate = true;
        }

        public override IEnumerator<WebTestRequest> GetRequestEnumerator()
        {
            // Initialize validation rules that apply to all requests in the WebTest
            if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
            {
                ValidateResponseUrl validationRule1 = new ValidateResponseUrl();
                this.ValidateResponse += new EventHandler<ValidationEventArgs>(validationRule1.Validate);
            }

            WebTestRequest request1 = new WebTestRequest("https://vsncts01/testwebsite");
            request1.ThinkTime = 9;
            request1.ExpectedResponseUrl = "https://vsncts01/testwebsite/";
            ExtractText extractionRule1 = new ExtractText();
            extractionRule1.StartsWith = "href=\"";
            extractionRule1.EndsWith = "\"";
            extractionRule1.IgnoreCase = false;
            extractionRule1.UseRegularExpression = false;
            extractionRule1.Required = true;
            extractionRule1.ExtractRandomMatch = true;
            extractionRule1.Index = 0;
            extractionRule1.HtmlDecode = true;
            extractionRule1.ContextParameterName = "href";
            request1.ExtractValues += new EventHandler<ExtractionEventArgs>(extractionRule1.Extract);
            yield return request1;
            request1 = null;
        }
    }
}
Return to top
Show: