セッション ID を示す URL にリダイレクトする ASP.Net サイトがあります。このような:
この ID は、すべてのリクエストで一意です。
標準の Visual Studio 2008/2010 Web テストを使用してこのサイトをテストすることは可能ですか? このデータをテストに提供するにはどうすればよいですか?
同じ ID を使用して、いくつかの異なるページを呼び出さなければなりません。
セッション ID を示す URL にリダイレクトする ASP.Net サイトがあります。このような:
この ID は、すべてのリクエストで一意です。
標準の Visual Studio 2008/2010 Web テストを使用してこのサイトをテストすることは可能ですか? このデータをテストに提供するにはどうすればよいですか?
同じ ID を使用して、いくつかの異なるページを呼び出さなければなりません。
はい、これを行うのは比較的簡単です。ただし、コード化された Web テストを作成する必要があります。
私の例では、セッション文字列を含む URL を返すログイン ポストがあります。ログイン ポスト リクエスト (request3) を列挙子に渡した直後に、次のように呼び出します。
WebTestRequest request3 = new WebTestRequest((this.Context["WebServer1"].ToString() + "/ICS/Login/English/Login.aspx"));
//more request setup code removed for clarity
yield return request3;
string responseUrl = Context.LastResponse.ResponseUri.AbsoluteUri;
string cookieUrl = GetUrlCookie(responseUrl, this.Context["WebServer1"].ToString(),"/main.aspx");
request3 = null;
GetUrlCookie は次のようなものです。
public static string GetUrlCookie(string fullUrl, string webServerUrl, string afterUrlPArt)
{
string result = fullUrl.Substring(webServerUrl.Length);
result = result.Substring(0, result.Length - afterUrlPArt.Length);
return result;
}
セッション Cookie 文字列を取得したら、後続の URL でリクエスト/投稿などに簡単に置き換えることができます。
WebTestRequest request4 = new WebTestRequest((this.Context["WebServer1"].ToString() + cookieUrl + "/mySecureForm.aspx"));
私のコードがとても荒いことをお詫びしますが、私のプロジェクトでは廃止され、コードベースの最初のバージョンから引き出されました - そしてそれは簡単だったと言ってくれて:)
負荷テストでは、アプリケーションによっては、テストを実行するたびに個別のログイン情報を提供するために呼び出すストアド プロシージャを作成する必要がある場合があります。
応答 URL を事前に決定することはできないため、ログイン ポストでは一時的に urlValidationEventHandler をオフにする必要があることに注意してください。これを行うには、validationruleeventhandler をローカル変数に保存します。
ValidateResponseUrl validationRule1 = new ValidateResponseUrl();
urlValidationRuleEventHandler = new EventHandler<ValidationEventArgs>(validationRule1.Validate);
したがって、必要に応じてオンとオフを切り替えることができます。
this.ValidateResponse -= urlValidationRuleEventHandler ;
this.ValidateResponse += urlValidationRuleEventHandler ;
別の方法は、このような独自のコードを作成することです (Visual Studio コードから反映され、大文字と小文字を区別しないように変更されています。
class QueryLessCaseInsensitiveValidateResponseUrl : ValidateResponseUrl
{
public override void Validate(object sender, ValidationEventArgs e)
{
Uri uri;
string uriString = string.IsNullOrEmpty(e.Request.ExpectedResponseUrl) ? e.Request.Url : e.Request.ExpectedResponseUrl;
if (!Uri.TryCreate(e.Request.Url, UriKind.Absolute, out uri))
{
e.Message = "The request URL could not be parsed";
e.IsValid = false;
}
else
{
Uri uri2;
string leftPart = uri.GetLeftPart(UriPartial.Path);
if (!Uri.TryCreate(uriString, UriKind.Absolute, out uri2))
{
e.Message = "The request URL could not be parsed";
e.IsValid = false;
}
else
{
uriString = uri2.GetLeftPart(UriPartial.Path);
////this removes the query string
//uriString.Substring(0, uriString.Length - uri2.Query.Length);
Uri uritemp = new Uri(uriString);
if (uritemp.Query.Length > 0)
{
string fred = "There is a problem";
}
//changed to ignore case
if (string.Equals(leftPart, uriString, StringComparison.OrdinalIgnoreCase))
{
e.IsValid = true;
}
else
{
e.Message = string.Format("The value of the ExpectedResponseUrl property '{0}' does not equal the actual response URL '{1}'. QueryString parameters were ignored.", new object[] { uriString, leftPart });
e.IsValid = false;
}
}
}
}
}