È stato utile?

Soluzione

Sì, è relativamente facile farlo. Tuttavia, dovrai creare un test web codificato.

Nel mio esempio abbiamo un post di accesso che restituirà l'URL inclusa la stringa di sessione. Subito dopo restituiamo la richiesta di post di accesso (request3) all'enumeratore che chiamo quanto segue.

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;

Dove GetUrlCookie è qualcosa del genere:

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

Una volta che hai la stringa del cookie di sessione, puoi sostituirla facilmente in qualsiasi URL successivo per richiesta / post per es.

WebTestRequest request4 = new WebTestRequest((this.Context["WebServer1"].ToString() + cookieUrl + "/mySecureForm.aspx"));

Mi scuso per il fatto che il mio codice sia così approssimativo, ma è stato deprecato nel mio progetto ed è stato estratto dalla prima versione della base di codice - e per aver detto che è stato facile :)

Per qualsiasi test di carico, a seconda dell'applicazione, potrebbe essere necessario elaborare una procedura memorizzata per chiamare per fornire informazioni di accesso distinte ogni volta che viene eseguito il test.

Nota, poiché l'URL di risposta non può essere determinato in anticipo, per il post di accesso dovrai disattivare temporaneamente urlValidationEventHandler. Per fare ciò, memorizzo validationruleeventhandler in una variabile locale:

        ValidateResponseUrl validationRule1 = new ValidateResponseUrl();
        urlValidationRuleEventHandler = new EventHandler<ValidationEventArgs>(validationRule1.Validate);

Quindi posso quindi accenderlo e spegnerlo come ho richiesto:

this.ValidateResponse -= urlValidationRuleEventHandler ;
this.ValidateResponse += urlValidationRuleEventHandler ;

L'alternativa è codificare il proprio come questo (riflesso dal codice di Visual Studio e modificato per non distinguere tra maiuscole e minuscole.

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