Share via


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)

Syntax

'Declaration
Public Property ExtractRandomMatch As Boolean
public bool ExtractRandomMatch { get; set; }
public:
property bool ExtractRandomMatch {
    bool get ();
    void set (bool value);
}
member ExtractRandomMatch : bool with get, set
function get ExtractRandomMatch () : boolean 
function set ExtractRandomMatch (value : boolean)

Property Value

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

Remarks

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.

Examples

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;
        }
    }
}

.NET Framework Security

See Also

Reference

ExtractText Class

Microsoft.VisualStudio.TestTools.WebTesting.Rules Namespace