Tuesday, May 19, 2009

Visual Studio Tweaking

Visual Studio every time says loading for first time...

To avoid this do

Click on the Tools > Options

Select "Import and Export Settings",

Edit the path for "Automatically save my settings to this file:" to a path on disk drive but not My Documents or any network drive.

Wednesday, May 13, 2009

IF Statment for MS-DOS batch file

SET FrontEnd="false"
SET BackEnd="false"
SET Translations="false"

IF %FrontEnd% == "true" GOTO FrontEnd
IF %BackEnd% == "true" GOTO BackEnd
IF %Translations% == "true" GOTO Translations
GOTO END

:FrontEnd
ECHO I am FrontEnd
GOTO END

:BackEnd
ECHO I am BackEnd
GOTO END

:Translations
ECHO I am Translations
GOTO END

:END

SET and GET values in DOS Batch file

Set a variable in DOS Batch file using following syntax

SET myVariable="Hello"

Get the value of the variable in DOS Batch file using following syntax

%myVariable%

Friday, March 13, 2009

Delete all Objects (Images) from Excel Workbook

Select the workbook
Press F5
Click Special
Select Objects
Click OK
Press Delete key from Keyboard

Friday, January 30, 2009

Install Flash Player for Firefox on Ubuntu

Install Flash Player on Ubuntu linux, use following command

sudo apt-get install flashplugin-nonfree

Thursday, January 29, 2009

Know the Ubuntu version

Use following command to know the Ubuntu OS version

cat /etc/issue

Monday, January 26, 2009

KDE on Install on Ubuntu Server

Install KDE desktop on Ubuntu Server

- sudo aptitude update

- sudo aptitude install kubuntu-desktop

Wednesday, January 21, 2009

Remove Hyperlink from multiple cells in Excel

In a blank cell, enter the number 1 .
Copy that cell.
Select the cells with the hyperlinks.
Right click on the seleted cells and click Paste Special.
Under operations, select multiply and click OK.

Tuesday, January 20, 2009

Get XML element inner text

XmlDocument xmlDocument = new XmlDocument(); // Creates new instance of XMLDocument

xmlDocument.Load(filePath); // Loads the XMLString which is XML file in one single string

XmlNode XMLElement = xmlDocument.SelectSingleNode("//data[@name='BrowserString1']//value"); // Gets the List of all XML elements foun

String value = XMLElement.InnerText;

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+ " ");
}
}

Friday, September 19, 2008

Ignore NUnit Test at Runtime

In order to ignore the test at runtime for NUnit framework i used the following code


bool flag;

[Test]
public void Test01()
{
if (flag == flase)
{
Assert.Ignore();
}
}

Friday, August 22, 2008

Execute MySQL commands from console

Using --execute one can query SQL statement from console instead on entering MySql prompt


mysql --user=root --database= healthy-dev_development --execute="SELECT * FROM users where users.email='attestuser1@gmail.com' "

Thursday, August 21, 2008

List Columns of the table

To list the columns of the MySQL table use the following syntax

show columns from table_name;

Bring Data from two tables using SQL JOIN

select T1.id, T2.email from application_details as T1 JOIN users as T2 ON T1.user_id=T2.id where T2.name='attestuser1';

Gmail using Selenium RC


{
// Login to Gmail and get the link
try
{
selenium.Open("http://www.gmail.com"); // Open Gmail Webpage
selenium.WaitForPageToLoad(sel_TimeOut);
selenium.WindowMaximize();
if (selenium.IsElementPresent("//a[contains(text(),'Sign out')]")) // If Already logged on, logout first
{
selenium.Click("//a[contains(text(),'Sign out')]");
selenium.WaitForPageToLoad(sel_TimeOut);
}
selenium.Type("//input[contains(@id,'Email')]", inv_InviteEmailAddress); // Enter Gamil User Account. GAMIL account should be set with HTML view
selenium.Type("//input[contains(@id,'Passwd')]", inv_InviteEmailPassword); // Enter Gmail Password
selenium.Click("//input[contains(@name,'signIn')]"); // Click on Gmail Sign In button
selenium.WaitForPageToLoad(sel_TimeOut); // Wait for web page to load. If page dont load after timeout test is failed
Thread.Sleep(Int32.Parse(com_UserThinkTime)); // Time taken by user to take action after page is loaded
selenium.Click("//*[contains(text(),'" + inv_InviteEmailSubject + "')]"); // Click on email with subject as pointed by variable inv_InviteEmailSubject
selenium.WaitForPageToLoad(sel_TimeOut); // Wait for web page to load. If page dont load after timeout test is failed
Thread.Sleep(Int32.Parse(com_UserThinkTime)); // Time taken by user to take action after page is loaded
selenium.Click("//a[contains(text(),'" + inv_InviteEmailRegisterLinkText + "')]"); // Click on link with text as pointed by variable inv_InviteEmailRegisterLinkText
selenium.WaitForPopUp(selenium.GetAllWindowNames()[1], sel_TimeOut);
selenium.SelectWindow(selenium.GetAllWindowNames()[1]);
selenium.WindowMaximize();
selenium.Type("//input[contains(@id,'user_password')]", inv_InviteEmailPassword); // Enter password
selenium.Type("//input[contains(@id,'user_password_confirmation')]", inv_InviteEmailPassword); // Enter password again
selenium.Check("//input[contains(@id,'terms_of_use_accepted')]"); // Accpet Terms of USe
selenium.Check("//input[contains(@id,'privacy_statement_accepted')]"); // Accept Privacy statment
Thread.Sleep(Int32.Parse(com_UserThinkTime)); // Time taken by user to take action after page is loaded
selenium.Click("//input[contains(@class,'sign_up_btn')]"); // Click on Signup button
selenium.WaitForPageToLoad(sel_TimeOut); // Wait for web page to load. If page dont load after timeout test is failed
Thread.Sleep(5000);
}
catch (SeleniumException selEx)
{
throw new Exception("GMAIL Something went wrong",selEx);
}
// End of Gmail
}

Wednesday, August 13, 2008

Reads Binary file and encodes it to Base64 string using C#.NET

public static string BinaryToBase64String(string filePath)
{
try
{
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); // Creates new file stream for binary file with read access
BinaryReader binaryReader = new BinaryReader(fileStream); // Creates the binary reader with file as input
byte[] binaryByteArray = binaryReader.ReadBytes((int)fileStream.Length); // Reads the bytes from binay file and stores into byte array
return Convert.ToBase64String(binaryByteArray); // Encodes the byte array to Base64 string and returns the string
}
catch (Exception ex)
{
return ex.Message; // Returns the exception message
}
}

Locate the element inside table row based on text inside row's cell

This is one of the powerfull XPATH query I have seen

selenium.Check("//tr[.//p[contains(text(),'AT Test User 1')]]//input[contains(@name,'members_new')]");

here //tr[.//p[contains(text(),'AT Test User 1')]] returns the table row which has p tag containing text AT Test User 1. Notice the . used here, which refers to the context node
And once that row is selected //input[contains(@name,'members_new')] locates the input element contained in that row.

Retrieve Value from Resource File using C#

// Here IPOhelper is the class name under which method with following implementation is defined. and file is the file path where resource filename (without extension) is located e.g. Namespace.FileName


string resourceValue = string.Empty;
try
{

ResourceManager resourceManager = new ResourceManager(file,typeof(IOHelper).Assembly);
resourceValue = resourceManager.GetString(key);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
resourceValue = string.Empty;
}