Thursday, 13 August 2009

My Answer(s) posted on Code Project web site Part-1

In this Blog i would like to share my Answers which i have posted on Code project.
reference: http://www.codeproject.com/script/Forums/Messages.aspx?fmid=4764307
Question: Can WatiN accept inputs from an Excel sheet
Can WatiN accept inputs form an excel sheet. this functionality was there in watir.
Is this available in WatiN.

Jawed: yes it is.for that you need to write simple C# code to read from excel sheet.see below
some example from my side.

public class CommonClassAutomation
{
static string connectionString
= "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=
D:/test.xls;Extended Properties=Excel 8.0;";
public static string inputText= string.Empty;

public void TC_googletest()
{


//before calling instance of browser read input from excel sheet.
readExcelsheet();
//Open instance of IE browser.
IE ie=new IE();
//Open Google.com in browser
ie.goto("www.google.com");
/*Provide input text in to google search box. which you have already having from
excel sheet.*/
ie.TextField(Find.ByName("q")).TypeText(inputText);
//Click on Search button.
ie.Button(Find.ByName("btnG")).Click();
}
//Method To read data from Excel sheet
public void readExcelsheet()
{
DbProviderFactory factory = DbProviderFactories.GetFactory
("System.Data.OleDb");
int inputCount=0;
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM ["+ sheetName+"$]";
try
{
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
if (dr.Read())
{
inputText= dr[1].ToString();
}
}
}
catch(Exception ex)
{
//To Do
}
}
}
}
}
Hope, it would be useful for you.
happy automation
Thanks,
Md.Jawed
Hi I'm working on WatiN tool. I've scenario where i need to check a checkbox and click on ok button in the popup window. i've used AttachtoIE method and used URL attribute to attach to the popup window. Now the problem is URL contains the ID value, which changes each time the popup appears.. so how to handle this or is there any other method other than AttachtoIE.
please give some suggestion thanking you.
Other Member: Yes I got it right, I ignored the query string part in the URL which used to change everytime.
for example,http://192.168.25.10:221/admin/UploadContent.aspx?opener=CustomContent_Add.aspxIn the above URL the second line is the query string which will be present after the question mark in the first line.so I used only the first line neglecting the second like this
IE popup = IE.AttachToIE(Find.ByUrl(Url, true);
this worked for me, hope this will help you
Jawed: Hi,@ninay_fz: nice reply
Just I want to add few points over here to make your piece of code to work with dynamic changing URL.In this situation is good practice to use Regular expression.
Add this name space to your code file.

using System.Text.RegularExpressions;

Use below code to generalize while accessing URL.
string Url= "http://192.168.25.10:221/admin/UploadContent.aspx";(or whatever string you want to put!!)
Regex reg = new Regex(Url);
IE popup = IE.AttachToIE(Find.ByUrl(reg , true));
Hope it would solve your problem.
Thanks,
Continue..............

Monday, 3 August 2009

Automatic Birthday scrap to your Orkut friends

This application would almost eliminate the human or user interaction to Orkut web site while sending Birthday Scarp to your Orkut friends.
Just copy this piece(wait for next blog for code) of code to your local folder. And click on .exe.
Not feeling to click on .exe :) then,
-> Go to control panel and add this application to Scheduled Tasks to run some predefined time.
And the predefined time this application would automatic run and will do the below mention steps. Even being in invisible mode :)

  1. The flow chart of this application is as below:-
    1. Open Internet explorer (optional).
    2. Go to Orkut website.
    3. Login with predefined credential.
    4. On successful login check that any friends birthday fall today.
    5. If yes. Click on leave scarp and leave a predefined birthday wishes to selected friend’s scrap book.
    6. Come back to home page.
    7. Check for the next friend birthday if his/her birthday fall today repeat steps 5 to 6.
    8. After above steps click on logout link.
    9. Logout from Orkut and close the browser.

I have developed this console application using C#, .net2.0.
And for interface with Orkut I used WATIN tool/framework 2.0.
Note: best part of this aaplication is that i m not asking your Orkut's details at all.cuz this code would be with you so,whenever you want you can stop it or run it :)
For this blog I have attached only video.
In next blog, I would like to publish the code with .exe and about the code description. Thanks!!!

My learning from this blog -: WATiN is not for Automation only. It can be used as API Interface .
Happy Orkuting :)

Thanks,
Md.Jawed

Monday, 27 July 2009

Run WATiN code thorugh web application

To run your WATiN Automation code/Script from web application or by using web application


Jus add this Header tag in .aspx file

< AspCompat="true" >

Example: - suppose that you have code file as MyWatinCode.aspx and MyWatinCode.aspx.cs.

Now go to MyWatinCode.aspx file and replace the top most Header Tag

<@ Page Language="C#" AutoEventWireup="true" CodeBehind=" MyWatinCode.aspx.cs" Inherits="AutomationTesting._ MyWatinCode" ValidateRequest="false">

By

<@ Page Language="C#" AutoEventWireup="true" CodeBehind=" MyWatinCode.aspx.cs" Inherits="AutomationTesting._ MyWatinCode" AspCompat="true" ValidateRequest="false" >

And run your Automation code in web Application .if still you are facing any issues please reply me.

Correction/Comments are always welcome :)

Happy Automation.....

Thanks,

Md.Jawed

Testing Definition

Today morning something spark in my mind regarding Definition of testing then I came up with my own explanation of testing.It’s fully based on my testing experience and by observing others.

Testing is an Art to execute your Knowledge, Skill and Desire.
Knowledge: - what to do and why?
Skill: - How to do?
Desire -: Want to do?

Correction is always welcome.

Wednesday, 8 July 2009

Afraid of writing blogs

Oooooooooooopppppppssssssss!!!!!!!!!! I took long gap for my second blog. Actually I was afraid of writing blogs. I was thinking that for writing blogs you need to have good writing skill and good technical knowledge of WATiN field. But after reading Pradeep Soundararajan blogs at http://testertested.blogspot.com/ I realized that I was wrong. Some contents which I would like to share with all of you.


1. You don't need to be an expert to blog but people commenting on your posts can help you to be an expert of the field.
2. As you peruse through the blog you would realize that you have improved a thousand leaps. It comes from practice and a blog helps you to practice writing.


Still I m working on WATiN blogs. Hope as soon as possible I will come up with that. :)