質問

セッションIDを示すURLにリダイレクトするASP.Netサイトがあります。このように:

  

http:// localhost /(S(f3rjcw45q4cqarboeme53lbx))/main.aspx

この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"));

コードが非常に荒いことをおpoびしますが、私のプロジェクトでは廃止され、コードベースの最初のバージョンから引き出されました-簡単だと言って:)

負荷テストの場合、アプリケーションによっては、テストを実行するたびに異なるログイン情報を提供するために呼び出すストアドプロシージャを考え出す必要がある場合があります。

注意:応答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;
                }
            }
        }
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top