ExtractText.ExtractRandomMatch 屬性
表示擷取值是否從 HtmlDocument 中的所有符合項隨機選擇。
命名空間: Microsoft.VisualStudio.TestTools.WebTesting.Rules
組件: Microsoft.VisualStudio.QualityTools.WebTestFramework (在 Microsoft.VisualStudio.QualityTools.WebTestFramework.dll 中)
語法
'宣告
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)
屬性值
型別:System.Boolean
布林值,表示擷取值是否從 HtmlDocument 中的所有符合項隨機選擇。
備註
如果所需的值是要從 XML 文件中的所有符合項隨機選擇,請將這個屬性設定為 rue。 您可以在建立擷取規則時設定此屬性。 然後,在 Web 效能測試執行階段引擎收到 WebTestRequest 的 HTML 回應之後,就會呼叫 Extract()。 呼叫 Extract() 時,並不會變更 ExtractRandomMatch 屬性值。
通常在 Web 效能測試程式碼的 GetRequestEnumerator 中,在建立 ExtractText 擷取規則之後、傳回 WebTestRequest 之前,就要設定 ExtractRandomMatch 屬性。
範例
下列範例會示範 Web 效能測試程式碼,其程式碼是透過程式碼產生的方式而產生。 程式碼產生之後未經手動修改。 當執行 yield return Request1; 陳述式時,會設定 ExtractRandomMatch 屬性。
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。