I have some difficulties understanding how the access method "Do not move cursor automatically" works for a web test data source. And the documentation out there seems to be far from exhaustive.
First of all, let's assume there is a simple web test with only one request. It uses a data source called DS with a table called StepList, that contains 5 rows.
The Access Method for the table is set to "Do not move cursor automatically" and the current test settings have "One run per data source row" enabled in the web test properties. The web test is not part of a load test.
In these conditions, the test is run 5 times, for each row, so it basically moves the cursor automatically. Is this intended?
Now, on to the practical question, which is the subject of this post.
My StepList table above has, among others, an identity column and a StepId column. The web test in question is actually called from another web test, and it's supposed to run only for the table rows that have a StepId set in the test context.
Id StepId
1 1
2 1
3 2
4 2
5 2
In order to achieve this, I followed the guidelines from here and wrote a web test plugin with the PreWebTest method looking like this:
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
string stepId = string.Empty;
if (e.WebTest.Context.ContainsKey(ContextParameterName))
{
stepId = e.WebTest.Context[ContextParameterName].ToString();
}
while (e.WebTest.Context["DS.StepList.StepId"].ToString() != stepId)
{
e.WebTest.MoveDataTableCursor("DS", "StepList");
}
}
The code above seems to work properly on the example table only if the stepId has the value "2". If it's "1", then MoveDataTableCursor throws WebTestEndOfDataException exception: "No more rows of data in a data source table with AccessMethod Unique".
I tried catching the exception and stopping the web test, but this doesn't work, as the test seems to never end.