Removing other’s workspace in TFS:

A common scenario while using a system used by some one else who earlier used the same TFS workspace.
You need to be either the owner of the workspace or have the Administer workspaces permission on the Team Foundation Server to perform this.
Open Visual studio Command prompt at

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC

tf workspace /delete [/server:servername] workspacename[;workspaceowner]

workspaceowner – other username or yourself
workspacename – Workspace name including the Computer Name

A GUI based free Team Foundation Sidekicks tool by Attrice Corp can also be used.
http://www.attrice.info/cm/tfs/

Comparing Dates in C# , selenium RC

Example to convert string to date time variable and also compare two date time variable.
string Firstdate = selenium.GetText(FirstDate_xp);
string Nextdate = selenium.GetText(Nextdate_xp);
DateTime date1 = Convert.ToDateTime(Firstdate);
DateTime date2 = Convert.ToDateTime(Nextdate);
int result = DateTime.Compare(date1, date2);
//Compare function returns
//0 if both dates are equal
//1 if date1 is recent than date2
//-1 if date2 is recent than date1

If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.

Selenium RC Coding using C Sharp #region

When you are writing a piece of selenium test script you can use the #region a feature of the Visual Studio Code Editor. This will let you specify a block of code that you can expand or collapse. Here is an example that shows the use of #region in the test method Typeall
#region Typeall
public void Typeall(string[] path, string[] value)
{
int len = path.Length;
for (int i = 0; i <= (len - 1); i++) { if (selenium.IsElementPresent(path[i])) { selenium.Type(path[i], value[i]); } } } #endregion

Selenium RC Test Framework using XML Data structure

In this example I will explain you how to create a Selenium RC test framework and have the test data including the xpaths in a XML data file. The scripts mentioned under are as following:
1. ObjectRef.cs file that has the test data and the xpaths defined, the code to read the XML Data file
2. FunctionReference.cs that has the TestInitialize and TestCleanup. The Test Data and Xpaths are in Data.xml.
3. Two test methods Google_AU and Google_US scripts (Google Search) – Google_AUTest.cs and Google_USTest.cs
Add System.Xml.dll to the reference library.

This example is in Visual Studio C#.

Code for ObjectRef.cs

[csharp]
using System.IO;
using System;
using System.Text;
using System.Diagnostics;
using System.Xml;
using System.Xml.XPath;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Selenium;
namespace GOOGLE
{
public class ObjectRef
{
//===========================================================================
// Define the test data
//===========================================================================
public string Google_au_url;
public string Googlesearch_au_tx;
public string SearchPagetitle_au_tx;
public string Google_us_url;
public string Googlesearch_tx;
public string SearchPagetitle_tx;
public string GoogleSearch_au_xp;
public string GoogleSearch_xp;
public string Google_textbox_xp;
public string Google_submit_xp;
//===========================================================================
// Define the xml data file path and other xml related objects
//===========================================================================
public ObjectRef DataFile;
public XmlDocument Doc;
public string FilePath;
public ObjectRef(string Path)
{
Doc = new XmlDocument();
FilePath = Path;
Doc.Load(Path);
}
public ObjectRef()
{ }
public string GetValue(string xPath)
{
string retVal = "";
XPathNodeIterator ni = GetValueNodeSet(xPath);
if (ni.Count > 0)
{
if (ni.Count > 1)
{
while (ni.MoveNext())
retVal = retVal + ni.Current.Value + ";";
}
else
{
ni.MoveNext();
retVal = ni.Current.Value;
}
}
return retVal;
}
private XPathNodeIterator GetValueNodeSet(string xPath)
{
XPathNodeIterator ni;
XPathNavigator nav;
nav = Doc.CreateNavigator();
ni = (XPathNodeIterator)nav.Evaluate(xPath);
return ni;
}
//===========================================================================
// Defining the Path of the xml data file
//===========================================================================
public static string ReadXMLDataFile()
{
String Path = Directory.GetCurrentDirectory();
Path = Directory.GetParent(Path).Parent.Parent.FullName + "\\Data.xml";
return Path;
}
//===========================================================================
// Reading the xml file – Test Data and Xpath values
//===========================================================================
public void GetXMLData()
{
ObjectRef DataFile = new ObjectRef(ReadXMLDataFile());
Google_au_url = DataFile.GetValue("//Google_AU/Google_url");
Googlesearch_au_tx = DataFile.GetValue("//Google_AU/Googlesearch_tx");
SearchPagetitle_au_tx = DataFile.GetValue("//Google_AU/SearchPagetitle_tx");
Google_us_url = DataFile.GetValue("//Google_US/Google_url");
Googlesearch_tx = DataFile.GetValue("//Google_US/Googlesearch_tx");
SearchPagetitle_tx = DataFile.GetValue("//Google_US/SearchPagetitle_tx");
GoogleSearch_au_xp = DataFile.GetValue("//Xpaths/GoogleSearch_au_xp");
GoogleSearch_xp = DataFile.GetValue("//Xpaths/GoogleSearch_xp");
Google_textbox_xp = DataFile.GetValue("//Xpaths/Google_textbox_xp");
Google_submit_xp = DataFile.GetValue("//Xpaths/Google_submit_xp");
}
}
}[/csharp]

Code for FunctionReference.cs

[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;
namespace GOOGLE
{
[TestClass]
public class FunctionReference : ObjectRef
{
public ISelenium selenium;
public StringBuilder verificationErrors;
[TestInitialize()]
public void SetupTest()
{
GetXMLData();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", Google_au_url);
selenium.Start();
selenium.SetTimeout("1200000");
selenium.WindowMaximize();
verificationErrors = new StringBuilder();
}
[TestCleanup()]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
}
}[/csharp]

Code for Google_AUTest.cs
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;
namespace GOOGLE
{
[TestClass]
public class Google_AUTest : FunctionReference
{
[TestMethod]
public void Google_AU()
{
string TestCase = "Google-AU";
selenium.Open(Google_au);
selenium.WaitForPageToLoad("20000");
selenium.WindowMaximize();
Console.WriteLine(TestCase + "Current location ->" + selenium.GetLocation());
selenium.Type(Google_textbox_xp, Googlesearch_au_tx);
selenium.Click(Google_submit_xp);
Thread.Sleep(10000);
if (selenium.IsElementPresent(GoogleSearch_au_xp))
{
Console.WriteLine(TestCase + "Selenium Wiki text is present on the search Page");
selenium.Click(GoogleSearch_au_xp);
selenium.WaitForPageToLoad("20000");
try
{
Assert.IsTrue(selenium.GetTitle().Equals(SearchPagetitle_au_tx));
Console.WriteLine(TestCase + "Selenium Wiki -> " + selenium.GetLocation() + " is opened with title ->" + selenium.GetTitle());
}
catch
{
Console.WriteLine(TestCase + "Selenium Wiki is not opened.Current page title ->" + selenium.GetTitle());
}
}
else
{
Console.WriteLine(TestCase + "Selenium Wiki text is NOT present on the search Page");
}
}
}
}
[/csharp]

Code for Google_USTest.cs
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;
namespace GOOGLE
{
[TestClass]
public class Google_USTest : FunctionReference
{
[TestMethod]
public void Google_US()
{
string TestCase = "Google-US";
selenium.Open(Google_url);
selenium.WaitForPageToLoad("20000");
selenium.WindowMaximize();
Console.WriteLine(TestCase + "Current location ->" + selenium.GetLocation());
selenium.Type(Google_textbox_xp,Googlesearch_tx);
selenium.Click(Google_submit_xp);
Thread.Sleep(10000);
if (selenium.IsElementPresent(GoogleSearch_xp))
{
Console.WriteLine(TestCase + "Selenium Remote-Control text is present on the search Page");
selenium.Click(GoogleSearch_xp);
selenium.WaitForPageToLoad("20000");
try
{
Assert.IsTrue(selenium.GetTitle().Equals(SearchPagetitle_tx));
Console.WriteLine(TestCase + "Selenium HQ ->" + selenium.GetLocation() + " is opened with title ->" + selenium.GetTitle());
}
catch
{
Console.WriteLine(TestCase + "Selenium HQ -> is not opened.Current page title ->" + selenium.GetTitle());
}
}
else
{
Console.WriteLine(TestCase + "Selenium Remote-Control text is NOT present on the search Page");
}
}
}
}
[/csharp]

Code Contributors: Bi Li & Rashmi Rajiv
If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.