October 2006 - Posts

With Ruby, comes in handy for WATIR Testing

I can't denied on this one. I can't do much with WATIR actually, like I can't even figure out how to do a basic for loop.

I think I can only be very productive in WATIR if I really understands Ruby language. I am kind of hestitate to pick up this language, as I will like to focus more on Microsoft Technologies. I tried to adopt Ruby back in 2 years ago, just I did not really like the syntax. I prefer strong typed language like C#.

Anyway my company is evaluating Visual Studio Team Edition for Software Testers. If it is a better product, maybe I will move into that one. At least I don't have to do so much of Ruby and stay focus.

WATIR is still a good web testing tool. For basic testing, I think there will not be an issue (try some luck with the tutorials and watir recorders). Just you can't leverage the power of it without knowing Ruby. Have fun.

 

Posted by chuawenching with no comments

ASP.NET 1.1 to ASP.NET 2.0 Migration #9

Just to share this tip :)

ASP.NET 1.1.

datagrid.CurrentPageIndex

ASP.NET 2.0

gridview.PageIndex

Light and easy tip. Cheers.

 

Posted by chuawenching with no comments

ASP.NET 2.0 CompareValidator - Compare Dates through custom user controls

“Hocus Focus” some magic spells … ok, my English is bad

 

I will like to share with you on what I find out on this. If you already know what ASP.NET 2.0 CompareValdator control is, just ignore the top part and read the bottom part. I hope it will help people.

 

ASP.NET 2.0 CompareValidator is quite a common control used by developers to validate input controls. I think the most common scenario is date comparisons. Assuming you have 2 text boxes, one start date and the other one end date. How do you check whether the end date more than the start dates?

 

You can achieve very easily without any extra tweaking like below:

 

<asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator" Operator="GreaterThan"

            Type="Date" ControlToCompare="txtStartDate" ControlToValidate="txtEndDate"></asp:CompareValidator>

 

There are a few key areas here that you need to take note on.

 

Attribute

Description

ErrorMessage

Your error description if there is an error triggered

Operator

There are a few types, equal, greaterthan, greater than and equal, datatypecheck

Type

Date, String (for my case I will choose Date)

ControlToCompare

Since I am comparing the end date greater than the start date, so ControlToValidate=EndDate and ControlToCompare=StartDate

ControlToValidate

 

In order to use ControlToCompare and ControlToValidate property, your input controls must be within the web form itself.

 

Now I have a new scenario. Assuming this:

 

You have user controls. 1 is for Start Date and 1 is for End Date. Within the user control, there are 1 text box and a button (which triggers a javascript calendar; pass the values to the textbox).

Drag these 2 user controls into a web form (default.aspx).

 

Try with the code above. Of course you won’t get it work, since there are no longer text boxes in the same form, but user controls instead. The question is how do you pass to ControlToCompare and ControlToValidate?

 

I had tried a lot of ways, like creating properties, played with ValidatationPageAttribute (something like that), passing ClientID, passing ID … just can’t work.

 

Then I found out a way. Try this in your page_load, and it will work J

 

    protected void Page_Load(object sender, EventArgs e)

    {       

        // Take note, passing UniqueID is very important

        // Not ClientID or ID, it won't work

        CompareValidator1.ControlToValidate = uclDate1.FindControl("txtEndDate").UniqueID;

        CompareValidator1.ControlToCompare = uclDate.FindControl("txtStartDate").UniqueID;           

    }   

 

You have to pass in the UniqueID and not others. Very important here.

 

I had placed the source code as below for your personal understanding. I do not have access to sgdotnet site to upload files L

 

// Default.aspx //

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<%@ Register Src="Date2.ascx" TagName="Date2" TagPrefix="uc2" %>

<%@ Register Src="Date1.ascx" TagName="Date1" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Testing Compare Validators with User Controls</title>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <uc1:Date1 ID="uclDate" runat="server"></uc1:Date1>

            <br />

            <br />

            <br />

            <uc2:Date2 ID="uclDate1" runat="server" />

            <br />

            <br />

            &nbsp;

            <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"

                Operator="GreaterThan" Type="Date" ControlToCompare="txtStartDate" ControlToValidate="txtEndDate"></asp:CompareValidator>

            <asp:Button ID="Button1" runat="server" Text="Button" /></div>

    </form>

</body>

</html>

 

// Default.aspx.cs //

 

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {       

        // Take note, passing UniqueID is very important

        // Not ClientID or ID, it won't work

        CompareValidator1.ControlToValidate = uclDate1.FindControl("txtEndDate").UniqueID;

        CompareValidator1.ControlToCompare = uclDate.FindControl("txtStartDate").UniqueID;           

    }   

}

 

// Date1.ascx //

 

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Date1.ascx.cs" Inherits="Date1" %>

Start Date <asp:TextBox id="txtStartDate" runat="server"></asp:TextBox>

 

// Date2.ascx //

 

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Date2.ascx.cs" Inherits="Date2" %>

End Date <asp:TextBox id="txtEndDate" runat="server"></asp:TextBox>

 

Note: There is still one problem about CompareValidator. Take note, when you specify the type as Date, it actually checks for dd/mm/yyyy. If your textbox display as dd-MMM-yyyy or 10-October-2006, it won’t validate. I had checked online and it seemed that you had to build your own custom validator for this. If anyone knows how I can achieve this in CompareValidator, let me know yeah J

 

Thanks.

Posted by chuawenching with 5 comment(s)

Visual Studio 2005 Debugger Visualisers

Hi,

Just in case you not sure what is a Visual Studio 2005 debugging visualisers, check this out:

http://community.sgdotnet.org/photos/chuawenching/picture42307.aspx

In order to see that, you need to click on the icon (looks like a zoom icon)

Try it now. You can see DataTables, DataSets, XML and even Images. Cool right :)

Posted by chuawenching with 2 comment(s)

Watir - Fix my calendar user control problem

Wow. I fixed my problem. I never had expected this would work. The calendar user control was developed back in year 2000 by my senior colleague. And he had left the company. I can't expose the user control source code, maybe that is why many people cannot assist me on this one.

Do you know one thing that saves my life? The Internet Explorer Developer Toolbar. It was very good. Wow.

The coolest feature I like about this tool, is that you can see View -> Class and ID Information. It was so much better than navigating through the view source. It helped me to solve the problem even faster. Thanks to Microsoft on this one.

I used to download this months ago, look at the folder ... just a DLL. How to use it? No idea? Maybe I didn't play or r&d enough. Just in case you not sure what I mean, do this in IE 7, believe it will work in IE 6 too.

http://community.sgdotnet.org/photos/chuawenching/picture41756.aspx

http://community.sgdotnet.org/photos/chuawenching/picture41757.aspx

When you enabled that feature as mentioned above, you will see this.

http://community.sgdotnet.org/photos/chuawenching/picture41758.aspx

Then you will wonder. How can a human being read like that? Thanks to the people who develop it? You can mouse over. Man, it saves me so much time.

You will be suprised to see this one. Like the example below, I had never expected there would be a label with an id of btday19.

http://community.sgdotnet.org/photos/chuawenching/picture41759.aspx 

I cannot find such keyword btday19 in the view source.

http://community.sgdotnet.org/photos/chuawenching/picture41761.aspx

Basically btday19 is a label. When you click this label, it will return (say 19-October-2006) back to the readonly textfield. In order to do this, you just have to code like this:

# Calendar
# click the calendar image icon 
ie.image(:id, "btDate").click
  
# click the calendar day item
ie.label(:id, "btday17").click

So you don't have to think too complex, like launching the javascript box. LOL. Anyway, I haven't done anything yet on WATIR using Unit Testing. Maybe later when I am free.

Watir is still quite powerful. :)

Posted by chuawenching with no comments

Watir - Can't set values for ReadOnly textfields

Now I found out what was causing my WatirRecorder not to record. Basically my calendar control has 2 controls. 1 readonly textfield and 1 image button.

You can't set values on the fly at the readonly textfield, if not it is not readonly right. :P

Except I can find a way to trigger the image button, launch the floating javascript window, and click the selected date.

Below are the errors I got from WatirMaker (written in Ruby, Scott's WatirRecorder is not able to show anything, hope his new version of WatirRecorder has improved features)

# DEBUG: Unsupported onfocusout tagname DIV (:id, '_ctl0_ContentPlaceHolder1_UclABC_XYZ_uclABC_XYZDetail_uclCalendar_divcalendar')
# DEBUG: Unsupported onfocusout tagname TD (:id, 'c17')
# DEBUG: Unsupported onclick tagname LABEL (:id, 'btday17')

c17 is actually a <td> tag. Just like this in view source:

<TR align="center">
<TD id="c15"></TD>
<TD id="c16"></TD>
<TD id="c17"></TD>
<TD id="c18"></TD>
<TD id="c19"></TD>
<TD id="c20"></TD>
<TD id="c21"></TD>
</TR>

Just how am I able to trigger this c17 on the fly? Since it is not a button, or an image ... not sure whether Watir can does this ... let me r&d more.

Cheers.

Posted by chuawenching with no comments

It was a long holiday

Just back from holiday ... 7 days no blogging starts to kill me :)

In Malaysia, we celebrate Deepavali and Hari Raya. So everyone is back to their hometown. I hardly had internet access, except once a while I had to use dial up to connect. The connection was too slow.

Anyway guess what happen to me on my holiday?

I got a car accident. Sigh :( Now my car is in the workshop, to claim insurance. My front bumper, and a few other things were damaged. Will take me near RM 2000.00 to fix it. So no choice, I will have to go with insurance. What a day? 2 weeks no car in KL. Have to take a taxi to work. 1 trip is RM 12.00 (without traffic jam). God help me, someone who can offers me car pool at office will be great.

 

Posted by chuawenching with no comments

WatirRecorder++ & Watir error: IE seems to crash

Just in case you all try to run WatirRecorder, whenever you press start to record and your Internet Explorer starts to crash, don't blame IE. I faced it a lot here :) 

Updated: This applies not only to Watir Recorder, but even you want to start running a watir script, by double clicking the *.rb file, the error will appear.

You will see this error.

http://community.sgdotnet.org/photos/chuawenching/picture41741.aspx

Just to skip this error, very simple. Just open an existing IE, and try running WatirRecorder. I think maybe it needs an existing iexplorer process running first, before can do anything.

This is based on my observation. Anyway I tried this with IE 7.0, not too sure about IE 6.0.

Cheers.

Posted by chuawenching with no comments

SWExplorerAutomation - is this tool good for web automated testing?

After facing problems with WatirRecorder, I decided to google on other tools. SWExplorerAutomation is actually quite cool. The light shined at me at first, then sudden I fell from the clift.

I am not saying the software is not cool. Just it is hard to use. When you miss a step, you have to redo from scratch. There is no help files, except you buy it and get the support. There is a developer guide you can download and a flash video to watch, but it isn't enough.

Everytime I generate the c# code and compile into .exe, I cannot get it to run. It just crashed.

I will still evaluate more. Maybe I miss out something. However it is definitely not easy to use this software compare to WatirRecorder. Need some training first I believe.

Posted by chuawenching with 2 comment(s)

Problems with WATIR

I was very happy when I read about such tool from Scott's blog http://www.hanselman.com/blog/CategoryView.aspx?category=Watir It was really a great tool at first. It solved a lot of my nightmare especially I needed to test the site manually (enter username, enter password, login, click that link, then that link, fill in the forms, bored :( )

There are 2 tools out there, one by Scott WatirRecorder++ which was developed in .NET and one developed entirely in Ruby. Before you install these 2 recorder tools, make sure you have ruby runtime and watir installed.

There are 2 issues that will caused your testing not to work.

a) If you are using WatirRecorder++ or the ruby version of it

It can't detect textarea html tags. When you have an asp.net textbox server control with multiline property set to true, it will generate the textarea tag. Trust me, your recorder will not detect it or gives you some errors. Sigh :(

The recoders will try to look for the ID attribute in textarea, but I am really not sure why it is not detected.

Everytime the recorder records something like a textbox:

ie.text_field(:id, '_ctl0_ContentPlaceHolder1_UclABC_DEF_uclSampleControl_txtAddress').set('your very long sentences'

However in order to solve it, you can manually edit the script and it will work. Instead of using :id, use :name like this:

*only for textarea

ie.text_field(:name, '_ctl0:ContentPlaceHolder1:UclABC_DEF:uclABC_DEFDetail:txtAddress').set('your very long sentences')

*it is easy to identify which is id or name attribute.

"Updated: Scott Hanselman suggested to me using this way... ie.text_field(:name, /txtAddress/).set('your very long sentences')"

*if you do this manually and not sure how you can get the id or name attribute, right click on your website using internet explorer, and select view source.

Just imagine you have so many multilines, you gonna code too. Hope the next version of recorder will solve this problem.

b) Neither the Recorder or doing this manually

If say you have a calendar control created in asp.net. There are a textbox and a button within it. When you click on the button, it will trigger javascript. The floating calendar will appear. Click one of the dates, and it will store the date value into that textbox.

I had tried to manually pass in the date into the textbox. But suprisingly when I ran the test script, it did not execute this. I can still force to click on that button. But I really have no idea how to trigger the floating calendar dates.

It had been a mystery to me. Hope I can resolve the issue fast. Or someone can shed some lights with me.

Thanks.

Posted by chuawenching with no comments

Feeling appreciated Part 2

I was suppose to blog this yesterday, but I was kinda busy with work.

It was the 3rd time that I was highlighted over my community contributions on Microsoft Technologies in my company portal. In the main portal, it was stated as Thought Leadership. Cool :) No wonder they nominate me for the leadership program (will only know whether I am involved in that program by December 2006).

http://community.sgdotnet.org/photos/chuawenching/picture40338.aspx

My company is very supportive to me on my community stuff :) Just imagine I can do community and taking a business leave. As long as I deliver my work. But anyway not many people like to do community during working hours haha :)

Posted by chuawenching with no comments

TechNation Day is coming

This is a community day event in Malaysia. Thanks to Yu Tsing for organizing it. Basically MIND, SPAN and ELITE communities are part of TechNation. Check it out here http://www.technation.com.my

The event will be on December 2, 2006. This session is kinda unique as she will be inviting one my company colleague to speak. Cool. But anyway my colleague is quite experienced and successful in the Malaysia IT industry.

Anyway the session is free but in Malaysia only.

For more information, check it here http://mind.com.my/blogs/events/archive/2006/10/19/TechNation-Day-December-2_2C00_-2006.aspx 

Posted by chuawenching with no comments

Feeling appreciated Part 1

Mark this day October 20, 2006. Earlier around 8.10 a.m., my project lead came to me with a plastic bag. Just like this one here:

http://community.sgdotnet.org/photos/chuawenching/picture40333.aspx

Then I asked her what was that? She said it was for you. I say what was inside? Then I opened it.

http://community.sgdotnet.org/photos/chuawenching/picture40334.aspx

2 maltas (i love malta) and 1 chocolate (yummy). Later I asked her what was is it for?

She smiled at me, and she told me it was for my hard work at project.

I am quite happy, and I feel appreciated a lot here. This is the company I dream of to work with when I am younger. I had never worked in such a company before. You know, it is not that I am greedy for the chocolate or maltas. Just the way they see me and value me.

Posted by chuawenching with no comments

Yesterday downloaded IE 7, and today it crashes

What a day? My IE 7 crashed around 8.22 a.m. Friday October 20, 2006. I just downloaded it yesterday, well it did slow down my machine. But it is still okay. But I never expect it to crash and see this.

http://community.sgdotnet.org/photos/chuawenching/picture40330.aspx

I only have 4 tabs, and not like I am doing anything funny. :(

Add on: It crashed again at 8.48 a.m here when I tried to close existing tabs. I think I am kinda regret installing IE 7.

Posted by chuawenching with no comments

ASP.NET 2.0 and SQL Server 2005 - Violation of PRIMARY KEY constraint

I faced this problem today. Well I admitted it was my fault. But the database wasn't design by me and I didn't noticed about primary/foreign keys. Maybe today I did not have enough sleep. Oops.

 

Anyway to share with you. If you try to run your program and you get this error or you execute the stored procedure directly in SQL Server 2005, seeing this error:

 

Msg 2627, Level 14, State 1, Procedure usp_table_Insert, Line 38

 

Violation of PRIMARY KEY constraint 'PK_table_XYZ'. Cannot insert duplicate key in object 'dbo.table_XYZ'.

 

The statement has been terminated.

 

First of all, what you need to do?

 

1. Open you table XYZ, right click at your primary key, then click on Relationship. From there you will know what are the primary and foreign keys. Assuming you don't design the database.

 

So what is the actual problem?

 

I have 2 tables. XYZ and ABC. XYZ contains the primary key. One of the fields which is AgencyID, is a foreign key to ABC table. So when you try to insert values into XYZ, you have to make sure that AgencyID that you input, must be available in table ABC.

 

Guess that explains something yeah. :)

Posted by chuawenching with no comments
More Posts Next page »