Ask a questionAsk a question
 

AnswerHow to fail a request

  • Tuesday, November 03, 2009 9:30 PMhalchal Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi

    So far I've always been able to do what was needed via .webtest.  Now there are few things that  require coding which I'm not too much familiar with. 
    When I create the code from webtest what language are we using?

    Here's what I'm trying to do:
    When I get to a certain page I extract the total (TotalCount = 5)
    After I add a user the total become 6 which I also extract.  (TotalCount2 = 6)
    Now I want to say

    extractionRule12.ContextParameterName = TotalCount2
    extractionRule10.ContextParameterName = TotalCount

    if

    {
    I want to fail the request here.  How do I do that"
    }

    Thanks

     

     

    (extractionRule12.ContextParameterName == extractionRule10.ContextParameterName + 1)

     

Answers

  • Thursday, November 05, 2009 7:12 AMEdwer FangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello,

    The language of coded web test depends on the project choice in the prompted dialog while creating a new web test through Test->New Test.

    To fail a request, you need to write a request level plug-in and set the outcome of request in it after upgrading to SP1. To use the context parameter in plug in, we could utilize 'e.WebTest.Context["ContextName"]' instead.

    The codes I tested on my machine are shown below and you may refer to:

    public class Class1:WebTestRequestPlugin
        {
            public override void PostRequest(object sender, PostRequestEventArgs e)
            {
                if (e.WebTest.Context["Total"].ToString()=="Dda")
                {
                    e.Request.Outcome = Outcome.Fail;
                }
            }
        }

    About how to write a request level plug in, you may refer to the following article :
    http://msdn.microsoft.com/en-us/library/bb514192.aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.

All Replies