Thursday 21 April 2011

DropDownList.FindByText() case in-sensitive

The default behavior of FindByText() and FindByValue() of ListBox is case sensitive. You have to write your own code to do a case-insensitive search against any list box. One of the UIs which I was working on recently had a country list box where "United Kingdom" had to be selected by default. It was done by binding a country list returned by the middle-tier to the listbox and then doing

CountryListBox.FindByText("United Kingdom").Selected = true


Everything was fine until the middle-tier code started returning a new list where it has "UNITED KINGDOM" in place of "United Kingdom" in the original list. As you know this breaks my code.

This caused me to think about a solution which can do it case-insensitively. And here is what I have come up with.


foreach (ListItem countryListItem in CountryListBox.Items)
{
if (countryListItem.Text.ToLower().Equals("united kingdom"))
{
_ddlCountry.SelectedIndex = -1;
_ddlCountry.Items.FindByText(countryListItem.Text).Selected = true;
}
break;
}


FYI

String.Compare Method (String, String, Boolean) allows to to do case insensitve comparison when you pass the third parameter as true.

Click here to read more about String.Compare()

How to check whether an element exists using jQuery

There might be different ways of doing this. One is using the length property of jQuery selector as shown in the below code snippet

if ($("#elementid").length > 0){
// element exists, do something here
}

Align radio button with corresponding label

You might have spent time to align the label against radio button or checkbox when you use RadioButton, RadioButtoList, CheckBox, CheckBoxList in ASP.NET. It can be fixed by using CSS vertical-align propery.

Example :

label, input[type="radio"]{
vertical-align:middle;
}

Or if you want to apply it for all the input fields

input, label{
vertical-align:middle;
}

This works for IE8, Firefox3.6 and Chrome as well. I may not work for IE6. Worth testing if your are targeting your site for IE6 users.

Tuesday 12 April 2011

First-Party and Third-Party cookies

Websites save cookies in your computer for the purpose of recognising your specific browser / computer combination, were you to return to the same site.

All cookies have an owner which tells you who the cookie belongs to. The owner is the domain specified in the cookie.

The word "party" refers to the domain as specified in cookie; the website that is placing the cookie. So, for example, if you visit www.helloeveryone.com and the domain of the cookie placed on your computer is www.helloeveryone.com, then this is a first-party cookie. If, however, you visit www.helloeveryone.com and the cookie placed on your computer says www.goodbye.com, then this is a third-party cookie.

Increasing numbers of people are either manually blocking third-party cookies, or deleting them reguarly. The cookies being deleted / blocked are third-party party cookies, as opposed to less problematic first-party cookies.

Why do far fewer people block first-party cookies? The reason for this is primarily that it is very difficult to surf the internet without accepting these cookies. First party cookies are necessary in order for you to be recognised as an individual. Any site that you login to as an individual requires a way of identifying you as "you". Hotmail, Yahoo, Gmail, online banking, ebay, Amazon, etc.

Additionally, anti-spyware software and privacy settings do not target first-party cookies.

How does this affect tracking systems, when people block / delete cookies?

A: All visits will still be recorded, but a person who has deleted the cookies will not be recognised as the same (returning) visitor.

When cookies are in place, and not blocked or deleted, total visitor counts will remain comparatively low. If a person constantly deletes cookies, they will be counted as a new "unique" visitor with every subsequent visit.

How Google Analytics works?

Google Analytics works by the inclusion of a block of JavaScript code on pages in your website. When visitors to your website view a page, this JavaScript code references a JavaScript file which then executes the tracking operation for Analytics. The tracking operation retrieves data about the page request through various means and sends this information to the Analytics server via a list of parameters attached to a single-pixel image request.

The data that Google Analytics uses to provide all the information in your reports comes from these sources:
  • The HTTP request of the visitor
  • Browser/system information
  • First-party cookies

How the Tracking Code Works

In general, the Google Analytics Tracking Code (GATC) retrieves web page data as follows:

  1. . A browser requests a web page that contains the tracking code.
  2. . A JavaScript Array named _gaq is created and tracking commands are pushed onto the array.
  3. . A <script> element is created and enabled for asynchronous loading (loading in the background).
  4. . The ga.js tracking code is fetched, with the appropriate protocol automatically detected. Once the code is fetched and loaded, the commands on the _gaq array are executed and the array is transformed into a tracking object. Subsequent tracking calls are made directly to Google Analytics.
  5. . Loads the script element to the DOM.
  6. . After the tracking code collects data, the GIF request is sent to the Analytics database for logging and post-processing.




The data contained in the GIF request is the data sent to the Google Analytics servers, which then gets processed and ends up in your reports. Here is an example of only a portion of a GIF request:

http://google-analytics.com/__utm.gif?utmwv=4&utmn=769876874&utmhn=example.com&utmcs=ISO-8859-1&utmsr=1280x1024&utmsc=32-bit&utmul=en-us&utmje=1&utmfl=9.0%20%20r115utmcc=__utma%3D97315849.1774621898.1207701397.1207701397.1207701397.1%3B

How GIF Requests Are Classified

A GIF request is sent to the Analytics servers in the following cases and classified according to the table below (Page, Event, Transaction, Item, Var). In each of these cases, the GIF request is identified by type in the utmt parameter. In addition, the type of the request also determines which data is sent to the Analytics servers. For example, transaction and item data is only sent to the Analytics servers when a purchase is made. Visitor, page, and system information is only sent when an event is recorded or when a page loads, and the user-defined value is only sent when the _setVar method is called.



Requests classified as interaction requests will impact the bounce rate calculations for your page or site. Bounce rate is referred to as a single-page visit to your site, but is strictly defined as a single interaction request during a user session. For this reason, a bounce rate for a page is also affected by ecommerce transactions and event tracking requests. This is because these features co-exist with page tracking and, when they are triggered, they result in additional interaction requests to the Analytics servers.

click here to read more.

Friday 8 April 2011

Test Automation for Web Applications

Many, perhaps most, software applications today are written as web-based applications to be run in an Internet browser. The effectiveness of testing these applications varies widely among companies and organizations. In an era of highly interactive and responsive software processes where many organizations are using some form of Agile methodology, test automation is frequently becoming a requirement for software projects. Test automation is often the answer. Test automation means using a software tool to run repeatable tests against the application to be tested. For regression testing this provides that responsiveness.

There are many advantages to test automation. Most are related to the repeatability of the tests and the speed at which the tests can be executed.

Test automation has specific advantages for improving the long-term efficiency of a software team’s testing processes.

Test automation supports:

* Frequent regression testing
* Rapid feedback to developers
* Virtually unlimited iterations of test case execution
* Support for Agile and extreme development methodologies
* Disciplined documentation of test cases
* Customized defect reporting
* Finding defects missed by manual testing

To Automate or Not to Automate?


It is not always advantageous to automate test cases. There are times when manual testing may be more appropriate. For instance, if the application’s user interface will change considerably in the near future, then any automation might need to be rewritten anyway. Also, sometimes there simply is not enough time to build test automation. For the short term, manual testing may be more effective. If an application has a very tight deadline, there is currently no test automation available, and it’s imperative that the testing get done within that time frame, then manual testing is the best solution.

Selenium



There are a number of commercial and open source tools available for assisting with the development of test automation. Selenium is possibly the most widely-used open source solution.

Selenium is set of different software tools each with a different approach to supporting test automation. Most Selenium QA Engineers focus on the one or two tools that most meet the needs of their project, however learning all the tools will give you many different options for approaching different test automation problems. The entire suite of tools results in a rich set of testing functions specifically geared to the needs of testing of web applications of all types. These operations are highly flexible, allowing many options for locating UI elements and comparing expected test results against actual application behavior. One of Selenium’s key features is the support for executing one’s tests on multiple browser platforms.

Click here to read more about Selenium

Custom Variables in Google Analytics

Custom variables are name-value pair tags that you can insert in your tracking code in order to refine Google Analytics tracking. With custom variables, you can define additional segments to apply to your visitors other than the ones already provided by Analytics.

You'll get the most out of custom variables if you understand the basic visitor interaction model used in Google Analytics. In this model, the visitor interacts with your content over a period of time, and the engagement with your site is broken down into a hierarchy.


The diagram illustrates this model for a single visitor to your site, where each block represents the number of user sessions and interactions from that particular user.

Each level in this model is defined as follows:

* Visitor—the client that visits the site, such as the browser or mobile phone operated by a person.

* Session—the period of time during which the visitor is active on the site.

* Page—activity on the user's behalf which sends a GIF request to the Analytics servers. This is typically characterized by a pageview, but it can include:

o a pageview
o an event (e.g. click on "Add To Cart" button)


Syntax

_setCustomVar(index, name, value, opt_scope)

Points to Remember


  1. All parameteres are required except the last one.
  2. The sum of all your custom varaiables cannot exceed 5 in any given request.
  3. The length of the string used for the name and the length of the string used for the value must not exceed 64 bytes


Example

_gaq.push(['_setCustomVar', 1, 'User Type', 'Member', 2 ]);
_gaq.push(['_trackEvent', 'Shopping', 'Item Removal']);

Click here to read more about GA custom variables

Thursday 7 April 2011

Printing database diagram in a single page from SQL Server Management Studio

When you try to print database diagrams in SQL Server Management Studio most of the time things end up printing the diagram multiple pages. There is a work-around to this.

Right-Click on the diagram and select the option 'View Page Breaks'. Now you can rearrange your tables to avoid page breaks. Print it once you move all your tables into a single page.

"View Page Breaks" option is also available in "Dtabase Diagram" menu as well.