Can a Context variable be set from a Datasource?

I want to run a user registration recorded webtest for each username stored in a database.

I've:
- recorded such a test
- Added a datasource
- Added a context variable (sUsername)
- Set the Username page field to use the context variable

But I cannot see how to set the context variable from the datasource? The only thing that can be done in the context variable Properties window is set the value to static text. I tried using the same syntax that worked for setting the Username page field to the datasource value ... {{TestData1.Username.Username}} ... but that didn't work (it was treated as static text).

If I can bind the context variable to the datasource, I can use that variable elsewhere in the test.

Can this be done?

[760 byte] By [kklasman] at [2008-2-17]
# 1

For what I have seen this can not be done with a recorded test. You need to convert the test to a coded test and then assign the text value of the validation rule to the DataSource. The dataSource is available as property in the generated class and you can then just work the ADO way to get the correct table from the datasource and bind the field you would like.

Hope this helps

MarceldeVries at 2007-9-8 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 2
Hi,

Can you please give a small code snippet on how to do this in code.

Thank you.

Jesudhas at 2007-9-8 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 3
Sure,
that would look like this:
I USed a datasource to the Camino database using a native SQL provider and selected the Houses table. I also declared a DataBinding with Name CaminoDB1 refering the houses table the field name
The value I assign is available from the context and will be equivalent to the next row for ech iteration that is done.

namespace FunctionalTests {

using System;

using System.Collections.Generic;

using Microsoft.VisualStudio.QualityTools.WebTestFramework;

using Microsoft.VisualStudio.QualityTools.WebTestFramework.Rules;

[DataSource("CaminoDB1", "Provider=SQLNCLI.1;Data Source=tfsdata;Integrated Security=SSPI;Initial Catalog=CaminoDB", Microsoft.VisualStudio.QualityTools.WebTestFramework.DataBindingAccessMethod.Sequential, "Houses")]

[DataBinding("CaminoDB1", "Houses", "name", "CaminoDB1.Houses.name")]

public class WebTest1Coded : WebTest {

public WebTest1Coded() {

this.Proxy = null;

}

public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{

WebTestRequest request1 = new WebTestRequest
("http://localhost:63278/CaminoWebSite/Default.aspx");

request1.Method = "POST";

FormPostHttpBody request1Body = new FormPostHttpBody();

request1.Body = request1Body;

ValidationRuleFindText rule1 = new ValidationRuleFindText();

rule1.FindText = (string)Context["CaminoDB1.Houses.name"];

request1.ValidateResponse += new
EventHandler
<ValidationEventArgs>(rule1.Validate);

yield return request1;
}

}

}

Just to note that it would be very helpfull if microsoft just supported this as well for the non generated test scenario's of course.

Hope this Helps

MarceldeVries at 2007-9-8 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 4

>>Just to note that it would be very helpfull if microsoft just supported >>this as well for the non generated test scenario's of course.

I would just like to emphasize how useful this would be, and I hope Microsoft is looking into supporting this.

Thanks,

Eric

EricMorceau at 2007-9-8 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...

Visual Studio Team System

Site Classified