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' "
ASP.NET, C#.NET, CruiseControl.NET, Microsoft SQL Server, MS-DOS Batch, MySQL, nAnt, NodeJs, PowerShell, Python, Selenium RC, Redis, WebAii, Ubuntu
Friday, August 22, 2008
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;
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
}
}
{
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.
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;
}
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;
}
Wednesday, August 06, 2008
Locate Link using XPATH and Link Text
If you want to click on link on HTML with the text displayed as 'Sign out' use following for Selenium RC using C#
selenium.Click("//a[contains(text(),'Sign out')]");
selenium.Click("//a[contains(text(),'Sign out')]");
Friday, August 01, 2008
Selenium Image Attributes
Get alternate text from image from HTML document. I use here Xpath query to locate image in the HTML Document
String deviceStatus = selenium.GetAttribute("//img/@alt");
String deviceStatus = selenium.GetAttribute("//img/@alt");
Subscribe to:
Posts (Atom)