Search code examples
visual-studioweb-testing

How do I access data driven values in a web test plugin


I have a data driven web performance test in Visual Studio 2012. I want to access the values from the data source within a PreRequest() or a PostRequest() plugin. The values are being accessed already for form post parameters via bindings like {{DataSource1.PaymentAccounts#csv.USER_ID}}.

My end goal is to write the values into a web log comment so the data source values of failed tests are easier to identify. So the values would be passed into a call of e.WebTest.AddCommentToResult(string.Format(...)).


Solution

  • The values are stored in the text context, so can just access the value with WebTestRequestPlugin code such as:

    object contextParameterObject;
    if ( e.WebTest.Context.TryGetValue("DataSource1.PaymentAccounts#csv.USER_ID",
                    out contextParameterObject) ) {
        string contextParameter = contextParameterObject.ToString();
        e.WebTest.AddCommentToResult(contextParameter);
    }
    else {
        throw new WebTestException("'DataSource1.PaymentAccounts#csv.USER_ID' not found");
    }
    

    By default the context only holds those fields (columns) of the data source that are explicitly used in the web test file. To make all the fields in the datasource available set the Select columns property of the datasource file to Select all columns.