Tuesday, November 25, 2008

Overwrite the nAnt Property Value from Commnad Line

In order to change nAnt build file property from command line, set the overwrite attribute of the property to false.



When you execute nant from command line using

nant -D:ServerAddress=google.com

the ServerAddress is set to google.com

Wednesday, November 19, 2008

Read XML Elements using Selenium RC

In order to get XML element using Selenium RC (.NET client) I used the following strategy,


  1. Open XML document in webbrowser using

    selenium.Open(http://www.servername.com/my.xml);

  2. Use selenium GetText method (which returns the inner text of XML tag). I used XPATH expression to locate the tag inside XML document

    String myText = selenium.GetText("//plan[1]");


Thursday, November 13, 2008

Get nAnt Build File Property Attribute Programatically

In order to read nAnt build file and get the Property value I wrote the following code in C#.NET

static String GetNANTAttributeValue(String filePath, String tagName, String attribute1Name, String attribute1Value, String attribute2Name)
{
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(filePath);
XmlNodeList xmlNodeList = xmlDocument.GetElementsByTagName(tagName);
String result = "";
for (int i = 0; i < xmlNodeList.Count; ++i)
{
if (xmlNodeList[i].Attributes[attribute1Name].Value == attribute1Value)
{
result = xmlNodeList[i].Attributes[attribute2Name].Value;
break;
}
}
return result;
}
catch (Exception)
{
throw new Exception("Unable to Retrive XML Attribute, The tagName Provided: " +tagName+ " ");
}
}