Wednesday, 16 December 2009
How to get Source code of the target web page
Then I thought do we have any alternative to solve this problem?
I searched/goggled somewhere here and there. At last I got some snip of code.
I customize the code in such a way that it helped me in 2 ways.
1. When source code functionally is disable of the target web page/web site.
2. When something failed (no control found) during running of automation code then just get the source code and save it in text file. Latter it would help me to find out why my automation code failed or Check for the controls id/value/text etc on that web page.
Below is the code for that
public void GetSourceCode()
{
try
{
//Target website/web page
string strUrlOfWebPage = "http://jawedm.blogspot.com";
//Location to store source code in text file.
string strTextFileLocation = "c://SourceFile.txt";
System.Net.WebRequest request = System.Net.HttpWebRequest.Create(urlOfWebPage);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)
request.GetResponse();
System.IO.Stream responseStream = response.GetResponseStream();
System.IO.StreamReader readerSource = new System.IO.StreamReader
(responseStream);
string strSourceForTextFile = readerSource.ReadToEnd();
readerSource.Close();
System.IO.File.WriteAllText(strTextFileLocation, strSourceForTextFile);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
Thanks ,
Md. jawed
Sunday, 13 September 2009
FXCop an Automated tool for code review
Rules defined by FXCop
Report generation
fig: Report generated by FXCop.
Integrate with Visual studio
In the Visual Studio .NET IDE, navigate to Tools -> External Tools option;
on click of External tool one new dialog box would open.click on Add button to display the new configuration dialog box as below:
fig: Adding FXCop to External toll
On new windows set the parameter as below:1. ADD: Click on ADD button to add an Fxcop as external tool
2. Title: provide an external toll name (something like FxCop).
3. Command: To set the value of the Command text box, browse to the location where FxCop
is installed, and select FxCopCmd.exe. (in my case it is at
C :\Program Files\Microsoft FxCop 1.36\FxCopCmd.exe)
Files\Microsoft FxCop 1.36\Rules" /consolexsl:"C:\Program
Files\Microsoft FxCop 1.36 \Xml\VSConsoleOutput.xsl"
Some key arguments explained below:
• /c direct FXCop analysis to console or output window in IDE.
• /f:
Library (DLL), or a directory to browse for target assemblies
("D:\NWAAutomationCode\bin\Debug").
• /p:
Corresponding FXCop project file.
• /s - Indicates FXCop to include the summary report with the informational message. • /r:
5. Initial Directory : Set the Initial Directory to the location where FxCopCmd should start.
("C:\Program Files\Microsoft FxCop 1.36")
6. Select the Use Output window check box.
7. Click OK.
at last we have integarted FXCop to our VS.Net.
Now to Run this FXCop for Code Review analysis Click on Tools, under drop down menu select FXCop as shown below:
On click of FXCop ,the FXCop Engine would start Analysis our code w.r.t selected Rules and The analysis results will be posted in the "Output Window" of VS with the rule name, code file name, and error details as shown below ,The developer can click on the relevant FXCop error and navigate to the source-code to understand the problem and then fix it.
Please feel free to put some comments.
References:
1. http://msdn.microsoft.com/en-gb/magazine/cc188721.aspx
2. http://www.binarycoder.net/fxcop/html/tutorial.html
3. http://www.codeproject.com/KB/dotnet/FxCopIntegrateVSNET.aspx
4. http://articles.techrepublic.com.com/5100-10878_11-6152637.html
Thanks,
Md.Jawed
Saturday, 12 September 2009
How to handle JavaScript pop-up window, file download handler in WATiN
1.1 Suppose that we have scenario like on click of button/link etc we are calling a JavaScript function and that JavaScript function will open a HTML pop up window. To handle this the WATiN code would be something like :
//Open our main site
IE ie = new IE(“go to some URL”);
//Create an Instance of ConfirmDialogHnadler;
AlertAndConfirmDialogHandler myHandler = new AlertAndConfirmDialogHandler();
//Declare an object of HTMLDialog
HtmlDialog myModalHandler;
ie.AddDialogHandler(myHandler);
//The button that opens the HTML dialog must be clicked with NO WAIT
ie.Link(Find.ByText("Click to see a demo popup window")).ClickNoWait();
//Hook the PopUp by title/name/type etc.
myModalHandler = ie.HtmlDialog(Find.ByTitle(new Regex("MyTestPopUp")));
//Click on button which is on PopUp window.
myModalHandler.Button(new Regex("BtnSubmit")).ClickNoWait();
1.2 In this scenario through JavaScript function if we are opening a POP-Up and that pop up windows is coded in aspx. Then the WATiN code will be something like this :
//go to main window
IE ie = new IE("gotosomeURL");
//Click on link to open popup window
ie.Link(Find.ByText("open popup")).ClickNoWait();
//Hook the new popup by url/type/title etc
string url = "MYpopUp.aspx";
Regex regUrl = new Regex(url);
IE br = IE.AttachToIE(Find.ByUrl(
//Type some text in text box which is on popup window
br.TextField("TextBox1").
//Click on button which is on popup window
br.Button(new Regex("Button1")).ClickNoWait(
2. Download a zip file from popup window
//Open an Main website(i m assuming that you r not signout of codeproject we
IE ie = new IE("http://www.codeproject.
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler("BirthDayScrapOrkut.zip");
//Add this instance of FileDownloadHandler to DialogHander
ie.AddDialogHandler(fileDownloadHandler)
//User DialogWatcher to watch open filehandler windows
using (new UseDialogOnce(ie.
{
//Click on link Download source code to open zip file
ie.Link(Find.ByText("Download source - 1.9 MB")).ClickNoWait();
//Wait for 30 seconds to handle File Download
fileDownloadHandler.
fileDownloadHandler.
}
//Remove Watcher
ie.DialogWatcher.RemoveAll(