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?
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