The approach below uses the SetExtractedValue and GetExtractedValue instead
All references to the variables can be through DataDriven bindings.
- Create an XML file
<GlobalValues>
<GlobalValue>
<TelerikHomeFirstname>"Michael"</TelerikHomeFirstname>
<TelerikOwnerSurname>"Jackson"</TelerikOwnerSurname>
<TelerikHomeEmailAddress>"Neverland Ranch"</TelerikHomeEmailAddress>
<TelerikNickName>"King of POP"</TelerikNickName>
<TelerikURL>"http://google.com/"</TelerikURL>
<TelerikDBUsername>"telerik"</TelerikDBUsername>
<TelerikDBPassword>"TelerikPassword"</TelerikDBPassword>
<TelerikDBDatabase>"telerikdb"</TelerikDBDatabase>
<TelerikCheckCountUsername>"tlk"</TelerikCheckCountUsername>
<TelerikCheckCountPassword>"password"<TelerikCheckCountPassword>
</GlobalValue>
</GlobalValues>
Add a new Script Step. In the OnBeforeTestStarted method
add the following code
public override void OnBeforeTestStarted()
{
string globalVarsFile = @"c:\<path>\myglobalvarsfile.xml";
try
{
if(!File.Exists(globalVarsFile))
{
// an error has occurred
Log.WriteLine("Error: FILE" + globalVarsFile + "DOES NOT EXIST");
Assert.IsTrue(false);
}
else
{
Log.WriteLine("File found" +globalVarsFile);
}
XDocument globalVarsXML = XDocument.Load(globalVarsFile);
var queryResult =
from gl in globalVarsXML.Element("GlobalValues").Element("GlobalValue").Elements()
select gl;
foreach(XElement x in queryResult)
{
SetExtractedValue(x.Name.ToString(), x.Value.ToString());
}
}
catch(FileNotFoundException fnfe)
{
Log.WriteLine("IO Error occurred: " + fnfe.Message);
}
catch(IOException ioex)
{
Log.WriteLine("IO Error occurred: " + ioex.Message);
}
}