views:

179

answers:

0

I had a general question about extracting code from a visual studio web test. I used the "generate code" option of a web test and got the following:

using System; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.WebTesting; using Microsoft.VisualStudio.TestTools.WebTesting.Rules;

namespace SignsOfLife { public class SignsOfLifeCoded : WebTest {

    public SignsOfLifeCoded() {
        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("http://localhost/site/client/default.aspx");
        yield return request1;
        request1 = null;

        WebTestRequest request2 = new WebTestRequest("http://localhost/site/login.aspx");
        request2.ThinkTime = 5;
        request2.QueryStringParameters.Add("c", "clientcode", false, false);
        ExtractHiddenFields extractionRule1 = new ExtractHiddenFields();
        extractionRule1.Required = true;
        extractionRule1.HtmlDecode = true;
        extractionRule1.ContextParameterName = "1";
        request2.ExtractValues += new EventHandler<ExtractionEventArgs>(extractionRule1.Extract);
        yield return request2;
        request2 = null;

        WebTestRequest request3 = new WebTestRequest("http://localhost/site/login.aspx");
        request3.Method = "POST";
        request3.ExpectedResponseUrl = "http://localhost/site/user/home.aspx";
        request3.QueryStringParameters.Add("c", "clientcode", false, false);
        FormPostHttpBody request3Body = new FormPostHttpBody();
        request3Body.FormPostParameters.Add("__LASTFOCUS", this.Context["$HIDDEN1.__LASTFOCUS"].ToString());
        request3Body.FormPostParameters.Add("__EVENTTARGET", this.Context["$HIDDEN1.__EVENTTARGET"].ToString());
        request3Body.FormPostParameters.Add("__EVENTARGUMENT", this.Context["$HIDDEN1.__EVENTARGUMENT"].ToString());
        request3Body.FormPostParameters.Add("__VIEWSTATE", this.Context["$HIDDEN1.__VIEWSTATE"].ToString());
        request3Body.FormPostParameters.Add("__EVENTVALIDATION", this.Context["$HIDDEN1.__EVENTVALIDATION"].ToString());
        request3Body.FormPostParameters.Add("Login1$UserName", "username");
        request3Body.FormPostParameters.Add("Login1$Password", "password");
        request3Body.FormPostParameters.Add("Login1$LoginButton", "Log In");
        request3.Body = request3Body;
        yield return request3;
        request3 = null;
    }
}

}

What I wanted to do is basically put this test into a separate service to run throughout the day for purposes of health checking. I basically want to make sure that users are able to log in throughout the day. What process should I use to get the test into something like a console app? I was running into issues with debugging the webtest code. Like how would I correctly call the GetRequestEnumerator method and respond to it from code?

Thanks.