Verrouillé Webform Variables 101

  • 09 Maret 2012 20:37
     
     

    Hi, 

    Very basic question on Webform Variables.

    1. How to get theTextBox values in my webtest plugin?

    2. How to get posted data?

    Details: 

    I've created a webtest plugin that overrides PreWebTest, in which I want to grab what's currently being entered on the web forms, and do further processing (eg, appending current date & time). 

    Body must be 4 to 60000 characters long


Semua Balasan

  • 09 Maret 2012 20:38
     
      Memiliki Kode

    Continued:

    Source page : Default.aspx

     <form id="form1" action ="Default2.aspx" method="post" runat="server">            
    <table>           
    <tr>               
    <td><asp:TextBox ID="
    TextBox1" Text="T521" runat="server"></asp:TextBox></td>           
    </tr>               
    </table>       
    <table>           
    <tr>               
    <td>                   
    <asp:Button ID="Submit" runat="server" Text="Submit" /></td>           
    </tr>       
    </table>             
    </form>

  • 09 Maret 2012 20:38
     
      Memiliki Kode

    Continued:

    Destination page : Default2.aspx

    <form id="form1" runat="server">    
    <div>       
    <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label>   
    </div>   
    </form>

    I want to grab what's currently being entered in TextBox1, append current date & time to it, than post the form. In Default2.aspx, I want to changed the Label1 to be, TextBox1: <value of TextBox1>. 

    How can I do that? 

    Thanks a lot for your help.


  • 09 Maret 2012 20:59
     
     

    Q3: I want to put in Context Parameter a variable named Today, with value of 

    String.Format("{0:ddd, MMM d, yyyy}",  DateTime.Today). 

    How can I do that? 

    Thanks

  • 09 Maret 2012 23:51
     
     Jawab Memiliki Kode

    Hi Smetah,

    This is a plugin that will generate a Context Parameter called Today with the Format specified in your post. This will happen in the PreWebTest event before any requests are fired.

     public class TodayContextParam : WebTestPlugin
        {
            public override void PreWebTest(object sender, PreWebTestEventArgs e)
            {
                e.WebTest.Context["Today"] = DateTime.Now.ToString("ddd, MMM d, yyyy");
            }
        }


    http://blogs.msdn.com/rogeorge

    • Ditandai sebagai Jawaban oleh smetah 12 Maret 2012 13:35
    •  
  • 10 Maret 2012 0:47
     
     Jawab

    What you want to do here is use an extraction rule to dynamically 'extract' the value from the response in the HTML on the client side for your Text. So, there are a number of built in extraction rules , and for this one a simple ExtractText rule, where you set the StartsWith and EndsWith properties to the surrounding tags in the HTML output should do the trick.

    The extraction rule puts the value in a context parameter so you can use it wherever you need to reference it. If you reference it in code then it would be in form of WebTest.Context["NameOfContextParam"].ToString() if you were getting the value for example. So the extraction rule gets you whatever is there when the response comes back from the server and stores it in the Context Parameter. Then you can do whatever to that Context Parameter value, such as appedning dates/time to it and then wherever you have bound this in your requests querystring / form post parameters it will use this value when your request is made.

    This blog has an example of adding a Context Parameter by using the playback viewer, and you can search for other examples.

    http://blogs.msdn.com/b/slumley/archive/2009/05/28/vs-2010-feature-web-test-playback-enhancements.aspx


    http://blogs.msdn.com/rogeorge

    • Ditandai sebagai Jawaban oleh smetah 12 Maret 2012 13:35
    •  
  • 10 Maret 2012 3:03
     
     

    Thanks rogeorge, You've been most helpful.

    Let me ask one more question before I mark everything as answer,

    Having extracted the values into context parameter, what's the best plugin place to do my further processing?

    I'm still not too sure if it is PreWebTest or PreTransaction, or something else.

    Thanks.

  • 12 Maret 2012 13:21
     
     Jawab

    Hi Smetah,

    Selecting the right event depends on what processing your doing, what is the source of the data you need to process and where will the data be used.

    PreWebTest event happens before any requests are made so you wont have any dynamic processing of data that you extracted from a request here, this is where you setup things in the context that are then subsequently available to all the items in the test.

    PreRequest & PreRequestDataBinding happen before the request they are bound to, so here is the place to process items before they are actually sent.

    PostRequest happens after a request is completed, and here is where you can do some post processing on data that you might have extracted from the responses.


    http://blogs.msdn.com/rogeorge

    • Ditandai sebagai Jawaban oleh smetah 12 Maret 2012 13:35
    •  
  • 12 Maret 2012 13:27
     
     

    Thanks rogeorge,

    Is this case, I would think that in

    Q101: How to use variables in Web Performance Test, Round 2

    The plugin should better override the PreRequest, instead of PreWebTest. Am I right?

  • 12 Maret 2012 13:33
     
     Jawab
    If your going to modify values in context parameters before requests then use the PreRequestDataBinding event.

    http://blogs.msdn.com/rogeorge

    • Ditandai sebagai Jawaban oleh smetah 12 Maret 2012 13:35
    •  
  • 12 Maret 2012 13:35
     
     
    Thanks a lot rogeorge, You've been most helpful.