I have created custom extraction rule and the property i need the properties to be data driven i.e. I want to attach a data source (CSV file). how do I go about it ?
Followings are the screen shots and code snippets that describes the problem
Code snippet for custom extraction rule class
public class CustomeExtractionClass : ExtractionRule
{
public string Name
{
get;
set;
}
public override void Extract(object sender, ExtractionEventArgs e)
{
// Code to extract text/values from Response Based On NAME(i.e. Property) value
received from UI
}
}
UI for Name property
Note : Textbox next to Name property
How do I make it Data driven ? just like the one we get while inserting FormPost parameters... here is the example
Note the dropdown button bottom right which pulls up the attached data sources... I want the Name property values to be attached to the same data source.... how do i go about it ???
Finally after spending many hours I was able to get the values from the CSV file into my custom extraction rule. I could not bind the CSV file column to the Extraction rule property, however i got the work around. here is what i was missing
[DataBinding("DataSource1", "mycsvfile#csv", "ProcessInstanceID", "MyProcessInstanceID")]
here are the steps to achieve it
Step 1 : Add data Source to WebTest (Skip if already added)
Step 2 : Generate Code from WebTest (Skip if already done)
Step 3 : Bind datasource (i.e. CSV file) columns by adding following lines of code just above the declaration of your webtest class.
[DataSource("DataSource1", "Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\customextractionrule\\mycsvfile.csv", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, Microsoft.VisualStudio.TestTools.WebTesting.DataBindingSelectColumns.SelectOnlyBoundColumns, "mycsvfile#csv")]
[DataBinding("DataSource1", "mycsvfile#csv", "ProcessInstanceID", "MyProcessInstanceID")]
public class WebTest2Coded : WebTest
{
Note : in above code "MyProcessInstanceID" is the name of context parameter which will be created by visual studio and value of CSV file column will be assigned to this context parameter. you can give any name you wish.
Step 4 : Access the value of the Context parameter in your custom extraction rule
public override void Extract(object sender, ExtractionEventArgs e)
{
string ProcessIDinCSvFile = e.WebTest.Context["MyProcessInstanceID"].ToString());