<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nizar Noorani</title>
	<atom:link href="http://nizarnoorani.com/feed" rel="self" type="application/rss+xml" />
	<link>http://nizarnoorani.com</link>
	<description>A Software Development Consultant, Mentor &#38; Enthusiast</description>
	<lastBuildDate>Thu, 10 May 2012 17:19:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Show/hide various sections of a page using JQuery and CSS</title>
		<link>http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css</link>
		<comments>http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css#comments</comments>
		<pubDate>Fri, 04 May 2012 15:51:40 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[show/hide sections]]></category>
		<category><![CDATA[toggle visibility]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=579</guid>
		<description><![CDATA[In this post I&#8217;ll go over how you can utilize JQuery and CSS classes to show/hide various parts across the different sections of a page without creating a mess! The Challenge You&#8217;ve got a wizard-like page with multiple steps and you want to be able to show/hide various elements based … <a href="http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll go over how you can utilize JQuery and CSS classes to show/hide various parts across the different sections of a page <i>without</i> creating a mess!</p>
<p><strong>The Challenge</strong><br />
You&#8217;ve got a wizard-like page with multiple steps and you want to be able to show/hide various elements based upon the current step.  Below is a dumbed-down example:</p>
<p><img alt="" src="http://nizarnoorani.com/wp-content/uploads/sections.png" title="Page Sections" class="alignnone" width="1100" height="560" /></p>
<p>The colored boxes represent the parts that are being shared across the various sections of the page. For instance, the green box is being shared by the &#8216;Image Selection&#8217; and &#8216;Order Confirmation&#8217; sections.  While the red box is being shared by all three sections.</p>
<p>So the challenge is: How do we show/hide these various parts across the sections of the page without making a mess?  And by mess, I refer to duplicate code and/or little <% if..then %> snippets scattered throughout the page.</p>
<p><strong>The Solution</strong><br />
By using some CSS/JQuery trickery, of course!  What we&#8217;ll do is introduce some CSS classes that we will then apply to the various parts for which we need to handle visibility.  Here are the classes that we will need:</p>
<ul>
<li>section &#8211; Represents a section</li>
<li>requestor &#8211; Represents the requestor section</li>
<li>image-selection &#8211; Represents the image selection section</li>
<li>confirmation &#8211; Represents the order confirmation section</li>
</ul>
<p>The CSS classes will then be applied to the various parts based upon the section inside which the part is to be shown:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div&gt;
  &lt;input type='hidden' id='section-to-show' /&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;td&gt;Request Type:&lt;/td&gt;
      &lt;td class='section requestor'&gt;
        &lt;select&gt;...&lt;/select&gt;
      &lt;/td&gt;
      &lt;td class='section image-selection confirmation'&gt;
        &lt;%= selectedRequestType %&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    ...
    &lt;tr&gt;
      &lt;td&gt;First Name:&lt;/td&gt;
      &lt;td&gt;&lt;%= firstName %&gt;&lt;/td&gt;
    &lt;/tr&gt; 
    &lt;tr&gt;
      &lt;td&gt;Last Name:&lt;/td&gt;
      &lt;td&gt;&lt;%= lastName %&gt;&lt;/td&gt;
    &lt;/tr&gt; 
    &lt;tr class='section requestor confirmation'&gt;
      &lt;td&gt;Email&lt;/td&gt;
      &lt;td&gt;&lt;%= email %&gt;&lt;/td&gt; 
    &lt;/tr&gt;
    ...
    ...
    &lt;tr class='section image-selection confirmation'&gt;
      &lt;td&gt;Image&lt;/td&gt;
      &lt;td class='section image-selection'&gt;
        Browse...
      &lt;/td&gt;
      &lt;td class='section confirmation'&gt;
        &lt;img src='..' /&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    ...
  &lt;/table&gt;
&lt;/div&gt;</pre></div></div>

<p>A few things to highlight:</p>
<p> &#8211; The hidden input field &#8216;section-to-show&#8217; indicates the section to display.  It&#8217;s value is set by the server-side code.<br />
 &#8211; There are two table columns inside the first table row.  Only one will be visible based up the section that is being displayed.<br />
 &#8211; The first name and last name table rows don&#8217;t have any classes applied to them.  This is because they are always visible.<br />
 &#8211; The last table row shown above gives an example of how you can make the visibility conditional for both the table row and the table column.<br />
 &#8211; I skipped various rows in the HTML form above to save some typing and to avoid being repetitive.</p>
<p>And now for the JQuery:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// hide all sections to begin with</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.section'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    current_section <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#section-to-show'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span> <span style="color: #339933;">+</span> current_section<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And there you have it &#8211; a cleaner alternative to showing and hiding various parts across the sections of a page!</p>
<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fshowhide-various-sections-of-a-page-using-jquery-and-css&text=Show%2Fhide+various+sections+of+a+page+using+JQuery+and+CSS" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fshowhide-various-sections-of-a-page-using-jquery-and-css" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fshowhide-various-sections-of-a-page-using-jquery-and-css&title=http%3A%2F%2Fnizarnoorani.com%2Fshowhide-various-sections-of-a-page-using-jquery-and-css&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fshowhide-various-sections-of-a-page-using-jquery-and-css&title=Show%2Fhide+various+sections+of+a+page+using+JQuery+and+CSS&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fshowhide-various-sections-of-a-page-using-jquery-and-css&title=http%3A%2F%2Fnizarnoorani.com%2Fshowhide-various-sections-of-a-page-using-jquery-and-css" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/showhide-various-sections-of-a-page-using-jquery-and-css/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing Integration Tests for ASP .NET with Selenium 2.0 &#8211; Part 2</title>
		<link>http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2</link>
		<comments>http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2#comments</comments>
		<pubDate>Mon, 16 Apr 2012 20:45:45 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[ASP .NET]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Integration Tests]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[integration testing]]></category>
		<category><![CDATA[integration tests]]></category>
		<category><![CDATA[re-use driver]]></category>
		<category><![CDATA[re-use login]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[selenuim 2.0]]></category>
		<category><![CDATA[speeding up tests]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=551</guid>
		<description><![CDATA[This is the second in a series of posts on writing integration tests for ASP .NET using the Selenium 2.0 web application testing system. In this post, I&#8217;ll go over how to write and run C# test-cases using Selenium 2.0. I&#8217;ve also provided a base-class that contains helper methods for … <a href="http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>This is the second in a <a href="http://nizarnoorani.com/tag/selenium">series</a> of posts on writing integration tests for ASP .NET using the Selenium 2.0 web application testing system.</p>
<p>In this post, I&#8217;ll go over how to write and run C# test-cases using Selenium 2.0.  I&#8217;ve also provided a base-class that contains helper methods for repetitive stuff like typing inside input fields.   The base-class also speeds up the tests by re-using the same driver and preserving logins across tests.</p>
<p><b>Getting ready to write your first test-case&#8230;</b><br />
Make sure your test project references the following assemblies:</p>
<p>- WebDriver.dll<br />
- WebDriver.Support.dll<br />
- Newtonsoft.Json.dll<br />
- Ionic.Zip.dll<br />
- Castle.Core.dll</p>
<p>Refer back to my <a href="http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1">first</a> post on Selenium to learn about how to configure Selenium and where to grab these DLLs from.</p>
<p><b>Your first test-case</b><br />
For the purposes of writing our test case, we will assume that we have a web application that allows a user to login, fill out a form and submit it.  Below are basic HTML elements that we care about:</p>
<p><b>Login.aspx</b></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">  &lt;input type=&quot;text&quot; id=&quot;userId&quot; /&gt;
  &lt;input type=&quot;password&quot; id=&quot;password&quot; /&gt;
  &lt;input type=&quot;submit&quot; id=&quot;btnLogin&quot; value=&quot;Log In&quot; /&gt;</pre></div></div>

<p><b>FillForm.aspx</b></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">  &lt;input type=&quot;text&quot; id=&quot;firstName&quot; /&gt;
  &lt;input type=&quot;text&quot; id=&quot;lastName&quot; /&gt;
  &lt;input type=&quot;text&quot; id=&quot;address1&quot; /&gt;
  &lt;input type=&quot;text&quot; id=&quot;city&quot; /&gt;
  &lt;input type=&quot;text&quot; id=&quot;state&quot; /&gt;
  &lt;input type=&quot;submit&quot; name=&quot;btnSubmit&quot; value=&quot;Submit&quot; /&gt;</pre></div></div>

<p>Here is what our test-class would look like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">using System<span style="color: #339933;">;</span>
using Microsoft.<span style="color: #660066;">VisualStudio</span>.<span style="color: #660066;">TestTools</span>.<span style="color: #660066;">UnitTesting</span><span style="color: #339933;">;</span>
using OpenQA.<span style="color: #660066;">Selenium</span><span style="color: #339933;">;</span>
using OpenQA.<span style="color: #660066;">Selenium</span>.<span style="color: #660066;">Firefox</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">namespace</span> Web.<span style="color: #660066;">UI</span>.<span style="color: #660066;">Tests</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#91;</span>TestClass<span style="color: #009900;">&#93;</span>
    <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> FillFormIntegrationTest
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">public</span> static string BaseUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://localhost:8080&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// the max. time to wait before timing out.</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">const</span> int TimeOut <span style="color: #339933;">=</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#91;</span>TestMethod<span style="color: #009900;">&#93;</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> CanFillAndSubmitFormAfterLogin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> driver <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FirefoxDriver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// we need to setup implicit wait times so that selenium waits for some time and </span>
            <span style="color: #006600; font-style: italic;">// re-checks if an element isn't found.</span>
            <span style="color: #006600; font-style: italic;">// This is useful to ensure that a page gets fully loaded before selenium tries to look for stuff.</span>
            driver.<span style="color: #660066;">Manage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Timeouts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ImplicitlyWait</span><span style="color: #009900;">&#40;</span>TimeSpan.<span style="color: #660066;">FromSeconds</span><span style="color: #009900;">&#40;</span>TimeOut<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            driver.<span style="color: #000066;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">GoToUrl</span><span style="color: #009900;">&#40;</span>BaseUrl <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/Login.aspx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;userId&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;testUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;foobar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;btnLogin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Assert.<span style="color: #660066;">AreEqual</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Fill out form&quot;</span><span style="color: #339933;">,</span> driver.<span style="color: #660066;">Title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;firstName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;User&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;lastName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;One&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;address1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;99 Test Street&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;city&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Test City&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;state&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;TX&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;btnSubmit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Assert.<span style="color: #660066;">IsTrue</span><span style="color: #009900;">&#40;</span>driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">CssSelector</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;confirm-label&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Text</span>.
                   <span style="color: #660066;">Contains</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Submission successful.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And there it is!  If you run this test case, you&#8217;ll see the Firefox browser come up and go through actions specified in the test case above.</p>
<p><b>Saving our fingers and speeding up our tests!</b><br />
If you happen to find the Selenium API a little verbose then you&#8217;re not alone.  I feel the same way.  Having to type &#8216;driver.FindElement(By.Name(&#8220;firstName&#8221;))&#8217; for every single action starts getting tedious pretty quick &#8211; even with IntelliSense!  The other issue that you&#8217;ll notice as soon as you have more than one test-case is that starting up the FirefoxDriver takes a bit of time.  What we really want is a way to create the driver once and then simply re-use it across all our tests.  Another pain point are logins.  For most apps, a great majority of tests will require that a user be logged in.  Furthermore, you&#8217;re likely re-use the same login across most of your test-cases.  Instead of having each of our tests log the user in every single time, why not skip the login process if the user is already logged in?  Both these changes will make a significant impact in speeding up our tests.  So let&#8217;s add them!  </p>
<p>Below is a base-level class that contains the improvements pointed out above and also provides some helper methods to give our fingers a break!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
    <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> BaseIntegrationTest
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">const</span> string BaseUrl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://localhost:8888&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// specify if our web-app uses a virtual path   </span>
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">const</span> string VirtualPath <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">const</span> int TimeOut <span style="color: #339933;">=</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">private</span> static int _testClassesRunning<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> static readonly IWebDriver StaticDriver <span style="color: #339933;">=</span> CreateDriverInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">private</span> static Login _currentlyLoggedInAs<span style="color: #339933;">;</span>
&nbsp;
        static BaseIntegrationTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            StaticDriver.<span style="color: #660066;">Manage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Timeouts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ImplicitlyWait</span><span style="color: #009900;">&#40;</span>
               TimeSpan.<span style="color: #660066;">FromSeconds</span><span style="color: #009900;">&#40;</span>TimeOut<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Pass in null if want to run your test-case without logging in.</span>
        <span style="color: #003366; font-weight: bold;">public</span> static <span style="color: #000066; font-weight: bold;">void</span> ClassInitialize<span style="color: #009900;">&#40;</span>Login login <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            _testClassesRunning<span style="color: #339933;">++;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>login <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                Logoff<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>IsCurrentlyLoggedInAs<span style="color: #009900;">&#40;</span>login<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                Logon<span style="color: #009900;">&#40;</span>login<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> static <span style="color: #000066; font-weight: bold;">void</span> ClassCleanup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">try</span>
            <span style="color: #009900;">&#123;</span>
                _testClassesRunning<span style="color: #339933;">--;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_testClassesRunning <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    StaticDriver.<span style="color: #660066;">Quit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>Exception<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// Ignore errors if unable to close the browser</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> IWebDriver Driver
        <span style="color: #009900;">&#123;</span>
            get <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> StaticDriver<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> <span style="color: #000066;">Open</span><span style="color: #009900;">&#40;</span>string url<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Driver.<span style="color: #000066;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">GoToUrl</span><span style="color: #009900;">&#40;</span>BaseUrl <span style="color: #339933;">+</span> VirtualPath <span style="color: #339933;">+</span> url.<span style="color: #660066;">Trim</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'~'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Click<span style="color: #009900;">&#40;</span>string id<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Click<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Click<span style="color: #009900;">&#40;</span>By locator<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> ClickAndWait<span style="color: #009900;">&#40;</span>string id<span style="color: #339933;">,</span> string newUrl<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            ClickAndWait<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> newUrl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #006600; font-style: italic;">/// Use when you are navigating via a hyper-link and need for the page to fully load before </span>
        <span style="color: #006600; font-style: italic;">/// moving further.  </span>
        <span style="color: #006600; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> ClickAndWait<span style="color: #009900;">&#40;</span>By locator<span style="color: #339933;">,</span> string newUrl<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            WebDriverWait wait <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> WebDriverWait<span style="color: #009900;">&#40;</span>Driver<span style="color: #339933;">,</span> 
                  TimeSpan.<span style="color: #660066;">FromSeconds</span><span style="color: #009900;">&#40;</span>TimeOut<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            wait.<span style="color: #660066;">Until</span><span style="color: #009900;">&#40;</span>d <span style="color: #339933;">=&gt;</span> d.<span style="color: #660066;">Url</span>.<span style="color: #660066;">Contains</span><span style="color: #009900;">&#40;</span>newUrl.<span style="color: #660066;">Trim</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'~'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertCurrentPage<span style="color: #009900;">&#40;</span>string pageUrl<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> absoluteUrl <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Uri<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Uri<span style="color: #009900;">&#40;</span>BaseUrl<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> VirtualPath <span style="color: #339933;">+</span> 
                   pageUrl.<span style="color: #660066;">Trim</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'~'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ToString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    
            Assert.<span style="color: #660066;">AreEqual</span><span style="color: #009900;">&#40;</span>absoluteUrl<span style="color: #339933;">,</span> Driver.<span style="color: #660066;">Url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertTextContains<span style="color: #009900;">&#40;</span>string id<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            AssertTextContains<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertTextContains<span style="color: #009900;">&#40;</span>By locator<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Assert.<span style="color: #660066;">IsTrue</span><span style="color: #009900;">&#40;</span>Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Text</span>.<span style="color: #660066;">Contains</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertTextEquals<span style="color: #009900;">&#40;</span>string id<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            AssertTextEquals<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertTextEquals<span style="color: #009900;">&#40;</span>By locator<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Assert.<span style="color: #660066;">AreEqual</span><span style="color: #009900;">&#40;</span>text<span style="color: #339933;">,</span> Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertValueContains<span style="color: #009900;">&#40;</span>string id<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            AssertValueContains<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertValueContains<span style="color: #009900;">&#40;</span>By locator<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Assert.<span style="color: #660066;">IsTrue</span><span style="color: #009900;">&#40;</span>GetValue<span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Contains</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertValueEquals<span style="color: #009900;">&#40;</span>string id<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            AssertValueEquals<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> AssertValueEquals<span style="color: #009900;">&#40;</span>By locator<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Assert.<span style="color: #660066;">AreEqual</span><span style="color: #009900;">&#40;</span>text<span style="color: #339933;">,</span> GetValue<span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> IWebElement GetElement<span style="color: #009900;">&#40;</span>string id<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> string GetValue<span style="color: #009900;">&#40;</span>By locator<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">GetAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> string GetText<span style="color: #009900;">&#40;</span>By locator<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Text</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Type<span style="color: #009900;">&#40;</span>string id<span style="color: #339933;">,</span> string text<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> GetElement<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            element.<span style="color: #660066;">Clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            element.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Uncheck<span style="color: #009900;">&#40;</span>string id<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Uncheck<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Uncheck<span style="color: #009900;">&#40;</span>By locator<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> Driver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>locator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>element.<span style="color: #660066;">Selected</span><span style="color: #009900;">&#41;</span>
                element.<span style="color: #660066;">Click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Selects an element from a drop-down list.</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Select<span style="color: #009900;">&#40;</span>string id<span style="color: #339933;">,</span> string valueToBeSelected<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> GetElement<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">FindElements</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">TagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            foreach <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> option <span style="color: #000066; font-weight: bold;">in</span> options<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>valueToBeSelected <span style="color: #339933;">==</span> option.<span style="color: #660066;">Text</span><span style="color: #009900;">&#41;</span>
                    option.<span style="color: #660066;">Click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> static IWebDriver CreateDriverInstance<span style="color: #009900;">&#40;</span>string baseUrl <span style="color: #339933;">=</span> BaseUrl<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> FirefoxDriver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>       
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> static bool IsCurrentlyLoggedInAs<span style="color: #009900;">&#40;</span>Login login<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> _currentlyLoggedInAs <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> 
                   _currentlyLoggedInAs.<span style="color: #660066;">Equals</span><span style="color: #009900;">&#40;</span>login<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> static <span style="color: #000066; font-weight: bold;">void</span> Logon<span style="color: #009900;">&#40;</span>Login login<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            StaticDriver.<span style="color: #000066;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">GoToUrl</span><span style="color: #009900;">&#40;</span>BaseUrl <span style="color: #339933;">+</span> VirtualPath <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/Logon.aspx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            StaticDriver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;userId&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span>login.<span style="color: #660066;">Username</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            StaticDriver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">SendKeys</span><span style="color: #009900;">&#40;</span>login.<span style="color: #660066;">Password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            StaticDriver.<span style="color: #660066;">FindElement</span><span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">Id</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;btnLogin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            _currentlyLoggedInAs <span style="color: #339933;">=</span> login<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> static <span style="color: #000066; font-weight: bold;">void</span> Logoff<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            StaticDriver.<span style="color: #000066;">Navigate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">GoToUrl</span><span style="color: #009900;">&#40;</span>
                VirtualPath <span style="color: #339933;">+</span> RedirectLinks.<span style="color: #660066;">SignOff</span>.<span style="color: #660066;">Trim</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'~'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            _currentlyLoggedInAs <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> Login
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">public</span> Login<span style="color: #009900;">&#40;</span>string username<span style="color: #339933;">,</span> string password<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Username <span style="color: #339933;">=</span> username<span style="color: #339933;">;</span>
            Password <span style="color: #339933;">=</span> password<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> string Username <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> <span style="color: #003366; font-weight: bold;">private</span> set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> string Password <span style="color: #009900;">&#123;</span> get<span style="color: #339933;">;</span> <span style="color: #003366; font-weight: bold;">private</span> set<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> override bool Equals<span style="color: #009900;">&#40;</span>object obj<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Login compareTo <span style="color: #339933;">=</span> obj <span style="color: #000066; font-weight: bold;">as</span> Login<span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>compareTo <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">return</span> compareTo.<span style="color: #660066;">Username</span> <span style="color: #339933;">==</span> Username <span style="color: #339933;">&amp;&amp;</span> 
                   compareTo.<span style="color: #660066;">Password</span> <span style="color: #339933;">==</span> Password<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> Logins
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">public</span> static Login UserOne
        <span style="color: #009900;">&#123;</span>
            get
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Login<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;user_1&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;foobar1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> static Login UserTwo
        <span style="color: #009900;">&#123;</span>
            get
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Login<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;user_2&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;foobar2&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Upon inheriting from BaseIntegrationTest class, our test-case will look like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">using System<span style="color: #339933;">;</span>
using Microsoft.<span style="color: #660066;">VisualStudio</span>.<span style="color: #660066;">TestTools</span>.<span style="color: #660066;">UnitTesting</span><span style="color: #339933;">;</span>
using OpenQA.<span style="color: #660066;">Selenium</span><span style="color: #339933;">;</span>
using OpenQA.<span style="color: #660066;">Selenium</span>.<span style="color: #660066;">Firefox</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">namespace</span> Web.<span style="color: #660066;">UI</span>.<span style="color: #660066;">Tests</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#91;</span>TestClass<span style="color: #009900;">&#93;</span>
    <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> FillFormIntegrationTest <span style="color: #339933;">:</span> BaseIntegrationTest
    <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#91;</span>ClassInitialize<span style="color: #009900;">&#93;</span>
        <span style="color: #003366; font-weight: bold;">public</span> static <span style="color: #000066; font-weight: bold;">void</span> ClassInitialize<span style="color: #009900;">&#40;</span>TestContext context<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
           ClassInitialize<span style="color: #009900;">&#40;</span>Logins.<span style="color: #660066;">UserOne</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#91;</span>ClassCleanup<span style="color: #009900;">&#93;</span>
        <span style="color: #003366; font-weight: bold;">public</span> static <span style="color: #000066; font-weight: bold;">void</span> ClassCleanup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            BaseIntegrationTest.<span style="color: #660066;">ClassCleanup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#91;</span>TestMethod<span style="color: #009900;">&#93;</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> CanFillAndSubmitFormAfterLogin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">Open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;~/FillOutForm.aspx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
            Assert.<span style="color: #660066;">AreEqual</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Fill out form&quot;</span><span style="color: #339933;">,</span> driver.<span style="color: #660066;">Title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Type<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;firstName&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;User&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Type<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;lastName&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;One&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Type<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;address1&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;99 Test Street&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Type<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;city&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Test City&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Type<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;state&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;TX&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Click<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;btnSubmit&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            AssertTextContains<span style="color: #009900;">&#40;</span>By.<span style="color: #660066;">CssSelector</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;confirm-label&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Submission successful.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Much better, don&#8217;t you think? <img src='http://nizarnoorani.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In my next and final post on Selenium, I&#8217;ll go over the use of cookies to simulate and test various scenarios when integrating with 3rd party software.</p>
<p>Cheers! </p>
<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-2-0-part-2&text=Writing+Integration+Tests+for+ASP+.NET+with+Selenium+2.0+%26%238211%3B+Part+2" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-2-0-part-2" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-2-0-part-2&title=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-2-0-part-2&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-2-0-part-2&title=Writing+Integration+Tests+for+ASP+.NET+with+Selenium+2.0+%26%238211%3B+Part+2&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-2-0-part-2&title=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-2-0-part-2" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Writing integration tests for ASP .NET with Selenium 2.0 &#8211; Part 1</title>
		<link>http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1</link>
		<comments>http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1#comments</comments>
		<pubDate>Wed, 11 Apr 2012 21:03:28 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Integration Tests]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[ASP .NET]]></category>
		<category><![CDATA[integration tests]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[selenuim 2.0]]></category>
		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=519</guid>
		<description><![CDATA[This is the first in a series of posts on writing integration tests for ASP .NET using the Selenium 2.0 web application testing system. UPDATE: This post was updated on April 15, 2012 to explain how to setup and configure Selenium 2.0. In this post, I explain what Selenium is, … <a href="http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>This is the first in a <a href="http://nizarnoorani.com/tag/selenium">series</a> of posts on writing integration tests for ASP .NET using the Selenium 2.0 web application testing system.</p>
<p><b>UPDATE</b>: This post was updated on April 15, 2012 to explain how to setup and configure Selenium 2.0. </p>
<p>In this post, I explain what Selenium is, why use it and how to setup and configure it.  In the next subsequent posts, I&#8217;ll do a code walk-thru and also share some advanced scenarios.</p>
<p><strong>What is Selenium?</strong><br />
The best description of Selenium is probably the one mentioned on their website:
<p>&#8220;Selenium automates browsers. That&#8217;s it. What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.&#8221;</p>
<p><strong>Why use Selenium?</strong><br />
There are other integration testing web frameworks out there such as <a href="http://watin.org/">WaitN </a> or the <a href="http://ltaf.codeplex.com/">Lightweight Test Automation Framework</a> for testing ASP .NET web apps.  So, why use Selenium?  Here are the main reasons why picked it:</p>
<ol>
<li>
Selenium allows you to record test scenarios manually (by browsing to specific pages and clicking buttons, etc.) as well as programmatically (by coding up a test case).  Thus the tool can be used by both developers and QA&#8217;s.  You can even use a combination of recorded test scenarios and C# test cases to integration test your application.
</li>
<li>One feature that I really liked is that you can export a recorded test scenario as a C# test-case!  This technique can be used to drastically speed up the Selenium learning curve since it spits out code that you can use inside C# test-case.  For instance, when you&#8217;re unsure how to code up a specific scenario you can manually record it and then export it to see what the code needs to look like.
</li>
<li>
The recorded scripts can be used as a tool to speed up manual testing.  For example, I never manually login into the web application that I am currently implementing anymore.  Instead I run a test scenario that I had previously recorded, conveniently named Login, that logs me in.  No more manually typing in username/password!  You can use this technique to directly land on specific pages and/or fill-in and submit forms as well.  This adds up to save you boat loads of time during your manual testing.
</li>
<li>
Finally, the test recorder is a small Firefox plugin and integrates real nice with Firefox.
</li>
</ol>
<p>Convinced?  Awesome!  Let&#8217;s move on to setting up Selenium&#8230;</p>
<p><strong>Initial Setup</strong><br />
There are two parts to setting up Selenium:</p>
<ol>
<li>Installing the Selenium IDE: A Firefox plugin that allows you to manually record test scenarios.  Find and download the Selenium IDE plugin from the <a href="http://seleniumhq.org/download/">Selenium Downloads</a> section.  After it downloads, fire up the Firefox browser -> Go to Add Ons from the Main Menu -> Click the Settings icon -> Select the Install Add-On From File option -> Click Install Add-On.
</li>
<li>Installing the Selenium 2.0 WebDriver for .NET: Accepts commands from your C# test cases and automates the browser.  Using the NuGet Package Manager Console, run the below commands to install the Selenium packages.  Make sure you select your test project as the &#8220;Default project&#8221; inside the Package Manager Console before running the commands.  This way the DLLs will get added to the correct project.<br />
</p>

<div class="wp_syntax"><div class="code"><pre class="bat" style="font-family:monospace;">Install-Package Selenium.WebDriver
Install-Package Selenium.Support</pre></div></div>

<p>Okay, at this point, we should be all set with Selenium.  Verify the following:</p>
<p>- You are able to record a test scenario:  Fire up Firefox.  On the Main Menu, under Web Developer, you should now see a Selenium IDE option.  Or you can use the Ctrl+Alt+S shortcut key to bring it up.  Click the record button on the top right, browse to goggle.com, and search for something.  Click the record button again to stop the recording.  Now try running the script by clicking the play button and see what happens.  Make sure you are already on the google.com page when you click the Play button.  Hopefully, it worked.  If not, call me.  I&#8217;ll help you out and I only charge a $150/hr.  Just kidding.  If it doesn&#8217;t work then try re-installing the plugin, I guess. <img src='http://nizarnoorani.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>- You are able to write and run C# integration test-cases using Selenium &#8211; This is what I go over in my <a href="http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-2-0-part-2">next post</a> on Selenium.</p>
<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-part-1&text=Writing+integration+tests+for+ASP+.NET+with+Selenium+2.0+%26%238211%3B+Part+1" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-part-1" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-part-1&title=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-part-1&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-part-1&title=Writing+integration+tests+for+ASP+.NET+with+Selenium+2.0+%26%238211%3B+Part+1&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-part-1&title=http%3A%2F%2Fnizarnoorani.com%2Fwriting-integration-tests-for-asp-net-with-selenium-part-1" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/writing-integration-tests-for-asp-net-with-selenium-part-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically creating input fields on tab via CoffeeScript and JQuery</title>
		<link>http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery</link>
		<comments>http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery#comments</comments>
		<pubDate>Tue, 10 Apr 2012 13:02:15 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[dynamic input field]]></category>
		<category><![CDATA[dynamic jquery]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=475</guid>
		<description><![CDATA[Below is my very own, very first, super-clean, super-sexy CoffeeScript snippet that dynamically appends input fields as the user tabs through the current input field. The source-code is on the left. On the right you can actually play with it and see it in action! inputId = 1; &#160; jQuery … <a href="http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[Below is my very own, very first, super-clean, super-sexy CoffeeScript snippet that dynamically appends input fields as the user tabs through the current input field. The source-code is on the left. On the right you can actually play with it and see it in action!
<div style="clear: both"><br /></div>
<div style="float: left;">


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">inputId <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
&nbsp;
jQuery <span style="color: #339933;">-&gt;</span> 
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#fields :input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span> <span style="color: #3366CC;">'keydown'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span>
    <span style="color: #000066; font-weight: bold;">if</span> isModifierKeyPressed e
      <span style="color: #000066; font-weight: bold;">return</span> 
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> e.<span style="color: #660066;">keyCode</span> <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">9</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#93;</span>
      e.<span style="color: #660066;">preventDefault</span>
&nbsp;
      <span style="color: #000066; font-weight: bold;">if</span> isLastActivity<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span> <span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span>
	addAnotherTextInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>
&nbsp;
isModifierKeyPressed <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span>
  e.<span style="color: #660066;">ctrlKey</span> or e.<span style="color: #660066;">altKey</span> or e.<span style="color: #660066;">shiftKey</span>
&nbsp;
isLastActivity <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>inputFieldId<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span>
  inputNumber <span style="color: #339933;">=</span> 
    <span style="color: #009900;">&#40;</span>Number<span style="color: #009900;">&#41;</span> inputFieldId.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'activity'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>
  inputNumber <span style="color: #339933;">==</span> inputId
&nbsp;
addAnotherTextInput <span style="color: #339933;">=</span> <span style="color: #339933;">-&gt;</span>
  inputId<span style="color: #339933;">++</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#fields&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span> getInputField inputId
&nbsp;
getInputField <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>inputId<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&lt;input type='text' id='activity#{inputId}' 
                 class='input-super-large' 
                 placeholder='Type something and then press tab' /&gt;&quot;</span></pre></div></div>



</div>
<div id="fields" style="float: right;">
<input id="activity1" class="input-super-large" type="text" placeholder="Type something and then press tab" />
</div>
<div style="clear: both;"></div>


<style type="text/css">
  .input-super-large { width: 250px; height: 30px; font-weight: 1.2em; display: block; }
</style>
<script type="text/javascript">
  var addAnotherTextInput, getInputField, inputId, isLastActivity, isModifierKeyPressed;

inputId = 1;
  jQuery(document).ready(function() {
    jQuery("#fields :input").live('keydown', function(e) {
      if (isModifierKeyPressed(e)) return;
      if (e.keyCode === 9 || e.keyCode === 13) {
        e.preventDefault();
        if (isLastActivity(jQuery(this).attr('id'))) addAnotherTextInput();
        jQuery(this).next().focus();
        return false;
      }
    });
  });

  isModifierKeyPressed = function(e) {
    return e.ctrlKey || e.altKey || e.shiftKey;
  };

  isLastActivity = function(inputFieldId) {
    var inputNumber;
    inputNumber = Number(inputFieldId.split('activity')[1]);
    if (inputNumber === inputId) return true;
  };

  addAnotherTextInput = function() {
    inputId++;
    return jQuery("#fields").append(getInputField(inputId));
  };

  getInputField = function(inputId) {
    return "<input type='text' id='activity" + inputId + "' class='input-super-large' placeholder='Type something and then press tab' />";
  };
</script>
<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fdynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery&text=Dynamically+creating+input+fields+on+tab+via+CoffeeScript+and+JQuery" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fdynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fdynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery&title=http%3A%2F%2Fnizarnoorani.com%2Fdynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fdynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery&title=Dynamically+creating+input+fields+on+tab+via+CoffeeScript+and+JQuery&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fdynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery&title=http%3A%2F%2Fnizarnoorani.com%2Fdynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/dynamically-creating-input-fields-on-tab-via-coffeescript-and-jquery/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting WordPress URL migrations to work when all else fails!</title>
		<link>http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails</link>
		<comments>http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails#comments</comments>
		<pubDate>Tue, 03 Apr 2012 12:55:35 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[Tips And Tricks]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[permalink]]></category>
		<category><![CDATA[url migration]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=439</guid>
		<description><![CDATA[Recently, I modified the permalinks for my blog posts from: http://nizarnoorani.com/index.php/archives/%postid% to just be: http://nizarnoorani.com/%postname% This new permalink structure will now apply to any new posts that I create. Which of course begs the question: Will the links to all my existing blog posts break?? And the answer sadly and … <a href="http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[Recently, I modified the permalinks for my blog posts from: <code>http://nizarnoorani.com/index.php/archives/%postid%</code> to just be: <code>http://nizarnoorani.com/%postname%</code>  

This new permalink structure will now apply to any <em><strong>new</strong></em> posts that I create.  Which of course begs the question:

Will the links to all my existing blog posts break??

And the answer sadly and obviously is: Yes, they will!

Can we fix this unfortunate issue?  Sure, we can!  And there are quite a few WordPress plugins that do exactly this.  A search for "Wordpress URL migration plugins" will serve up links to many such plugins.  One that I particularly liked and recommend is <a href="http://wordpress.org/extend/plugins/advanced-permalinks/" title="Advanced Permalinks" target="_blank">Advanced Permalinks</a>.

If installing/activating/configuring one of these plugins fixes your problem - great!  Things for me, however, weren't quite so easy.

For some reason, which I still haven't been able to figure out, none of the migration plugins worked for me!  Maybe its because my blog was originally hosted under Windows and then I later moved it to Linux.  Or maybe I wasn't configuring the plugins correctly.  Or maybe something else.  I don't know.  

Anyways, IF you are in the same boat then here is one <strong><em>hacky</em></strong> solution to get your existing permalinks working again.  Once again - Only do this IF you can't get the WP migration plugins to work!

Okay, here goes:

<ol>
<li>Log in to your WordPress Dashboard: http://yourwebsite.com/wp-login</li>
<li>Set up your new permalink structure by navigating to Settings -> Permalinks.  After you set up your new permalink structure, you'll notice that your existing permalinks will now be re-directed to a 404 Not Found page.  Browse to one of your existing permalinks to verify that this is the the case.</li>
<li>Okay, time to put in our little hack to get the existing permalinks working again.  Open up the WordPress 404 template page inside the WordPress editor by navigating to Appearance -> Editor and clicking on the 404 Template link on the right-hand side bar.</li>
<li>Insert the following code snippet just below the <code>get_header()</code> line:


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;script type='text/javascript'&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
     <span style="color: #666666; font-style: italic;">// extract the post_id from the URL. In my case, my existing permalink was of the </span>
     <span style="color: #666666; font-style: italic;">// structure http://nizarnoorani.com/archives/%postid%.</span>
     <span style="color: #666666; font-style: italic;">// modify the extraction code below for our particular structure as needed.</span>
     <span style="color: #000088;">$postId</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/archives/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">// again, modify the URL as needed to match your new permalink structure.</span>
         <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;window.location = 'http://nizarnoorani.com/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;';&quot;</span><span style="color: #339933;">;</span> 
     <span style="color: #009900;">&#125;</span>  
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;/script&gt;</pre></div></div>



Note: Be sure to modify the code snippet to match your specific new and old permalink structures!
</li>
<li>Save your changes. Your existing permalinks should start working again!</li>
</ol>
Basically, what we've done here is added some logic to extract the post_id from the old link, retrieve the post with that post_id from the database, construct the new URL and then re-direct the user to the new URL.

Cheers!
<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fgetting-wordpress-url-migrations-to-work-when-all-else-fails&text=Getting+WordPress+URL+migrations+to+work+when+all+else+fails%21" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fgetting-wordpress-url-migrations-to-work-when-all-else-fails" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fgetting-wordpress-url-migrations-to-work-when-all-else-fails&title=http%3A%2F%2Fnizarnoorani.com%2Fgetting-wordpress-url-migrations-to-work-when-all-else-fails&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fgetting-wordpress-url-migrations-to-work-when-all-else-fails&title=Getting+WordPress+URL+migrations+to+work+when+all+else+fails%21&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fgetting-wordpress-url-migrations-to-work-when-all-else-fails&title=http%3A%2F%2Fnizarnoorani.com%2Fgetting-wordpress-url-migrations-to-work-when-all-else-fails" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/getting-wordpress-url-migrations-to-work-when-all-else-fails/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To TDD or Not To TDD?</title>
		<link>http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion</link>
		<comments>http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion#comments</comments>
		<pubDate>Fri, 16 Mar 2012 15:49:30 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test first]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=434</guid>
		<description><![CDATA[Recently, I was involved in a discussion with a colleague of mine that was focused around TDD - Test-Driven Development. During the discussion he mentioned that he personally finds the process of coding up the method first and test later to be easier, natural and more efficient. Writing the test-first … <a href="http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[Recently, I was involved in a discussion with a colleague of mine that was focused around TDD - Test-Driven Development.  

During the discussion he mentioned that he personally finds the process of coding up the method first and test later to be easier, natural and more efficient.  Writing the test-first just seems more difficult to do and less efficient.  He then went on to state his reasons:  

He said, and I agree with him here, it's probably easier and feels natural because that's the way he has always programmed.  Create functionality and then test that functionality.  TDD flips that around and as result you have to "re-learn" development.  Something he wouldn't mind doing, expect that...

In his opinion, TDD is a slower way to code.  Here is his reasoning: A great majority of the time, you're going to change the code that you wrote to begin with - you will rename the class or method, move things around, change the number of parameters or throw away the first attempt and start again.  If you were to write the tests first then those tests would have to change as well! As a result, you're increasing the amount of effort involved.  It's much faster to just write the test after the code has been finalized.  

Until a year ago, those were my thoughts exactly.  Then one day (well, probably more like over a period of several months, several books and several articles) I finally found the missing piece to the puzzle.  The piece that made TDD possible for me without causing me spend countless hours making significant changes to my test cases because I would keep making significant changes to my code-base.  I realized what TDD actually states. Which is: Do NOT write a single piece of <strong>production-code</strong> before first writing a test for it.  And there it is, the missing piece to the puzzle - <strong><em>production-code</em></strong>!  

Ah ha, I said!  I finally get it!  In other words, if you're unsure how about the solution is going to look like or work - write non-production code first to work out ideas, fill-in the gaps in requirements, get your questions answered, and get a feel for what the overall solution will look like.  Then and only then are you ready to write production-code!

Here is the process I now follow during the development: 

1.  Write a spike or POC code to "brainstorm" what the solution might look like. Sometimes I spend quite a bit of time here.  Since in the brainstorming process you'll find out gaps in requirments or will have to go research the third-party product that you're planning use.
2.  Once you've got a good grip on what the overall solution might look like and how it's going to work, I throw away the spike (or at least put it out of sight).
3.  I then write a failing test case.
4.  Write code to make it pass.
5.  Back to Step 1 if I am unclear on what the next piece of functionality entails; otherwise, Back to Step 3.

So I mentioned that to him and he sort of agreed but not really.  He was sort of on the fence.  After further discussion we hit upon another point on why to follow TDD that really hit home for him.    Here is the example I gave him:

Consider the following:  You've got X number of test cases in place for a piece of existing functionality.  All of the tests pass and everything is working just fine.  Then you get a change request.  You make the change and then run all the tests.  They all pass.  Are you done?  It's a little difficult to say, isn't it?  Somewhat open to interpretation.  I've come across developers who think that they are done at this point because they didn't break any existing tests.  But they forgot to ask - have I added a test for the new change that I made?  

On the other hand, if we were to first write a failing test for the change request then there would be no debate on whether or not a test is needed.  This where TDD really shines and ensures that we've got tests for all of the functionality.  When pressure creeps in, and this is especially true for change requests, then the discipline to add tests after the fact even when all of the existing tests are passing becomes very hard to follow-through on.

Sorry for the long-winded ranting.  Hopefully you got something out of it. <img src='http://nizarnoorani.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> 
<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fto-tdd-or-not-to-tdd-that-is-the-discussion&text=To+TDD+or+Not+To+TDD%3F" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fto-tdd-or-not-to-tdd-that-is-the-discussion" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fto-tdd-or-not-to-tdd-that-is-the-discussion&title=http%3A%2F%2Fnizarnoorani.com%2Fto-tdd-or-not-to-tdd-that-is-the-discussion&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fto-tdd-or-not-to-tdd-that-is-the-discussion&title=To+TDD+or+Not+To+TDD%3F&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fto-tdd-or-not-to-tdd-that-is-the-discussion&title=http%3A%2F%2Fnizarnoorani.com%2Fto-tdd-or-not-to-tdd-that-is-the-discussion" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/to-tdd-or-not-to-tdd-that-is-the-discussion/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unobtrusive JavaScript with HTML 5</title>
		<link>http://nizarnoorani.com/unobtrusive-javascript-with-html-5</link>
		<comments>http://nizarnoorani.com/unobtrusive-javascript-with-html-5#comments</comments>
		<pubDate>Sat, 10 Mar 2012 20:46:02 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tips And Tricks]]></category>
		<category><![CDATA[custom data attributes]]></category>
		<category><![CDATA[html 5]]></category>
		<category><![CDATA[unobtrusive javascript]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=414</guid>
		<description><![CDATA[HTML 5 supports a new feature known as Custom Data Attributes. These attributes give us the ability to define custom attributes for ANY HTML tags. The only restriction is that the tag must start with "data-". For instance, we can add a custom attribute to a link as follows: &#60;a … <a href="http://nizarnoorani.com/unobtrusive-javascript-with-html-5"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[HTML 5 supports a new feature known as <a href="http://dev.w3.org/html5/spec/global-attributes.html#embedding-custom-non-visible-data-with-the-data-attributes">Custom Data Attributes</a>.  These attributes give us the ability to define custom attributes for ANY HTML tags.  The only restriction is that the tag must start with "data-".  For instance, we can add a custom attribute to a link as follows:


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">  &lt;a href=&quot;#&quot; data-search-by-type=&quot;&lt;value&gt;&quot;&gt;My link with custom attribute&lt;/a&gt;</pre></div></div>




This feature comes with a neat benefit that we no longer need ANY inline javascript inside our HTML content.  For instance, say, we've got a commonly-used javascript function that performs a search by searchType:


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> search<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> searchType<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   ...
   ...
<span style="color: #009900;">&#125;</span></pre></div></div>




Prior to HTML 5, we would invoke the function using inline javascript inside our HTML tags:


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;javascript:search('byName')&quot; class='search-link'&gt;Search By Name&lt;/a&gt;  
&lt;a href=&quot;javascript:search('byType')&quot; class='search-link'&gt;Search By Type&lt;/a&gt;</pre></div></div>




With the introduction of Custom Data Attributes, we can now completely do away with the in-line javascript and write the links as follows:


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;#&quot; data-search-by='byName' class='search-link'&gt;Search By Name&lt;/a&gt;
&lt;a href=&quot;#&quot; data-search-by='byType' class='search-link'&gt;Search By Type&lt;/a&gt;</pre></div></div>




We would then add the following to our common.js file that contains the search() function:


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.search-link&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> search<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data-search-by&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>




The Custom Data Attributes in HTML 5 gives us a benefit that is similar in nature to the benefits provided by the CSS model - namely, separations of concerns.  CSS enables us to separate content from the presentation of that content, thus enabling our HTML pages to follow a well-defined structure.

Similarly, with Custom Data Attributes we can now separate logic or functionality from HTML content.  This provides with the following benefits:
<ol>
  <li>We no longer need to pollute our HTML with in-line Javascript.</li>
  <li>Keeping all our Javascript functionality centralized makes it much easier to manage.</li>
  <li>The use of Custom Data Attributes increases code re-usability since they can effectively serve as parameters to our javascript functions.</li>
</ol>


<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Funobtrusive-javascript-with-html-5&text=Unobtrusive+JavaScript+with+HTML+5" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/unobtrusive-javascript-with-html-5']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Funobtrusive-javascript-with-html-5" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/unobtrusive-javascript-with-html-5']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Funobtrusive-javascript-with-html-5&title=http%3A%2F%2Fnizarnoorani.com%2Funobtrusive-javascript-with-html-5&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/unobtrusive-javascript-with-html-5']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Funobtrusive-javascript-with-html-5&title=Unobtrusive+JavaScript+with+HTML+5&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/unobtrusive-javascript-with-html-5']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Funobtrusive-javascript-with-html-5&title=http%3A%2F%2Fnizarnoorani.com%2Funobtrusive-javascript-with-html-5" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/unobtrusive-javascript-with-html-5']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/unobtrusive-javascript-with-html-5']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/unobtrusive-javascript-with-html-5/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>On conducting technical interviews&#8230;</title>
		<link>http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews</link>
		<comments>http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews#comments</comments>
		<pubDate>Wed, 07 Mar 2012 03:13:43 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Interviewing]]></category>
		<category><![CDATA[conducting interviews]]></category>
		<category><![CDATA[interview tips]]></category>
		<category><![CDATA[software developer interview]]></category>
		<category><![CDATA[technical interview]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=369</guid>
		<description><![CDATA[As a software consultant, I've both gone through and conducted a fair share of technical interviews. By conducting interviews, being interviewed and watching others interview I've learnt a few things myself. Below are some tips on what works and what doesn't when interviewing software developers... 1. Ask the candidate to … <a href="http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[As a software consultant, I've both gone through and conducted a fair share of technical interviews.  By conducting interviews, being interviewed and watching others interview I've learnt a few things myself.  Below are some tips on what works and what doesn't when interviewing software developers...

<strong>1.  Ask the candidate to write some code!</strong>

IMHO, this should be one of the first filters.  The coding question should be simple enough that it would take a decent coder less than 5 to 10 minutes to code.  The purpose here is to filter out the "talkers" from the "doers".  For instance, if the candidate is having trouble coding a method that reverses a string, then it doesn't really matter how many years for experience they have, what company they last worked at, or how big the project was!  If they are having trouble remembering the a string is char[], then they are not someone you want on your team.  

This little test may sound too easy or "something that anyone should be able to pull off", but you'll be surprised at how many candidates are be unable to write a simple method when asked to do so.

For interviews that are conducted remotely, you can have the candidate share their screen (I typically use Skype or Join.me), ask them to open up notepad and code the solution.

<strong>2.  Separate the behavioral interviews from the technical interviews</strong>

Be fair to the candidate - let them know ahead of time what sort of interview will be conducted and by whom.  It's very confusing for a candidate when behavioral questions are mixed-in with technical ones.  This is because behavioral interviews require answers that contain a different vocabulary and are geared towards a different audience.  The candidate that is answering a behavioral question is usually careful to answer the question at a high-level without getting into the nitty-gritty technical details.  The answer is more focused on their contribution, how well they worked with others, how issues were handled, etc.  Whereas a technical answer would cover things like: what specific technology was used, how was the functionality broken out, what sort of development model was used, what approaches did they take to test their own code, etc.

Letting the candidate know what sort of interview is being conducted and by whom will enable them to put forth clear and appropriate responses. 

Which brings to my third point... 

<strong>3.  Please have the candidate go through AT LEAST one technical interview!</strong>

It's surprising how many managers, that haven't looked at code in ages, feel they have sufficient knowledge to hire a software developer.  Software development is changing - rapidly!  The skill-set required 5 years ago (or even a year ago in some cases) is quite different from what's required today.  So you if haven't kept up, you will have no way of knowing whether a candidate is right or wrong when they tell you that an ORM is an Object-Role Model that allows you to map roles (yes, I did have a candidate tell me that).  By all means, have the managers do the behavioral interviews - which, by the way, is a crucial part of the selection process - but PLEASE leave the technical interviews to your technical folks.  If for some reason you're not in position where you can have your own developers do the technical interviews (and there are many valid reasons why this may be the case) then hire an outside consultant to conduct the technical interview.  

The last thing you want is someone who is adept at talking through the concepts and seems to knows all the technical buzz-words but is very poor when it comes to writing code.  And, for some odd reason, there are many "senior-level developers and architects" that are just that!

<strong>5.  Skip irrelevant questions - such as brain teasers</strong>

Instead, ask questions that require some creativity and thought to answer.  For instance, say you want to find out whether the candidate that is being interviewed for a web development position has the habit of looking at and thinking about the big picture.  One question that may help gauge this is: What are some common performance or security related issues that surround web development and what are some strategies to circumvent them?  It's okay if they can't fully the answer the question. What you are looking for is whether such thoughts and questions have crossed their minds and how much time they've spent thinking about such issues. 

Another example is to give them a user story from your actual project (after maybe simplifying it a little) and ask them to sketch an object model for the user story.  What you are looking for is: What sort of class names they come up with, what sort of methods these classes contain, whether the relationships among the classes are represented correctly, does their overall object-model look "clean" and easy to understand?

Another question that requires some brain-power and creativity is to give them a user story and ask them to come up with a list of test-cases for the user story.  

<strong>6.  Find out if they actually like (nay, <em>love</em>) software development!</strong>

Ask them if they are currently learning or have recently learned a new technology outside of work.  What was the last software development book they read?  How long ago?  What did they learn from it?  Any  mentors, role-models they follow?  Have they read or follow the following persons:  Uncle Bob, Martin Fowler, Scott Hanselman? (Big red flag if they haven't heard these names before).  Where do they see themselves a year from now, five years from now?

Lastly, please keep in mind that these are my opinions that I have reached through my own learning and experimentation.  You may or may not agree with them and they may or may not work for you - and that's as it should be.  Try them out if you'd like, modify them as you deem appropriate, and definitely invent your own. 

Conducting interviews, much like giving interviews, requires constant refinement.  Filtering out and selecting the right candidate out of a pool of qualified candidates is never easy.  Hopefully, the above tips will prove somewhat beneficial to you while searching for the right candidate.
<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fmy-thoughts-on-conducting-technical-interviews&text=On+conducting+technical+interviews%26%238230%3B" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fmy-thoughts-on-conducting-technical-interviews" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fmy-thoughts-on-conducting-technical-interviews&title=http%3A%2F%2Fnizarnoorani.com%2Fmy-thoughts-on-conducting-technical-interviews&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fmy-thoughts-on-conducting-technical-interviews&title=On+conducting+technical+interviews%26%238230%3B&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fmy-thoughts-on-conducting-technical-interviews&title=http%3A%2F%2Fnizarnoorani.com%2Fmy-thoughts-on-conducting-technical-interviews" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/my-thoughts-on-conducting-technical-interviews/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Embracing CRUD &#8211; to it&#8217;s full extent!</title>
		<link>http://nizarnoorani.com/embracing-crud-to-its-full-extent</link>
		<comments>http://nizarnoorani.com/embracing-crud-to-its-full-extent#comments</comments>
		<pubDate>Fri, 24 Feb 2012 16:38:16 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[modular design]]></category>
		<category><![CDATA[small classes]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=346</guid>
		<description><![CDATA[I watched a screen-cast recently on how Ruby on Rails takes CRUD (Create, Read, Update, Delete) to its very extreme in order to come out with a software design that is to create, understand and modify. Here is the link for it: Love the CRUD. After watching it, I couldn't … <a href="http://nizarnoorani.com/embracing-crud-to-its-full-extent"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[I watched a screen-cast recently on how Ruby on Rails takes CRUD (Create, Read, Update, Delete) to its very extreme in order to come out with a software design that is to create, understand and modify.  Here is the link for it: <a href='http://www.scribemedia.org/2006/07/09/dhh/'>Love the CRUD</a>.

After watching it, I couldn't help but think back to a past project of mine where we kept running into the issue where our controllers and service classes kept turning into gigantic monsters and we would struggle to break them.  The fact that we were stuck with an existing design that greatly contributed to this problem didn't help either.  Regardless, I think following the approach outlined in the screen cast would be a huge step in the right direction to help address this issue.

The screen-cast is somewhat lengthy so hope you can hang in there. <img src='http://nizarnoorani.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> 

Cheers!<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fembracing-crud-to-its-full-extent&text=Embracing+CRUD+%26%238211%3B+to+it%26%238217%3Bs+full+extent%21" style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/embracing-crud-to-its-full-extent']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fembracing-crud-to-its-full-extent" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/embracing-crud-to-its-full-extent']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fembracing-crud-to-its-full-extent&title=http%3A%2F%2Fnizarnoorani.com%2Fembracing-crud-to-its-full-extent&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/embracing-crud-to-its-full-extent']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fembracing-crud-to-its-full-extent&title=Embracing+CRUD+%26%238211%3B+to+it%26%238217%3Bs+full+extent%21&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/embracing-crud-to-its-full-extent']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fembracing-crud-to-its-full-extent&title=http%3A%2F%2Fnizarnoorani.com%2Fembracing-crud-to-its-full-extent" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/embracing-crud-to-its-full-extent']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/embracing-crud-to-its-full-extent']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/embracing-crud-to-its-full-extent/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JQuery snippet to detect keystrokes on the numeric key-pad.</title>
		<link>http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad</link>
		<comments>http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad#comments</comments>
		<pubDate>Thu, 23 Feb 2012 17:25:04 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tips And Tricks]]></category>
		<category><![CDATA[detecting keys]]></category>
		<category><![CDATA[detecting keystorkes]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[numeric keypad]]></category>
		<category><![CDATA[numeric keystrokes]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=309</guid>
		<description><![CDATA[The below JQuery snippet returns the character corresponding to the key that was pressed on the QWERTY keyboard or the numeric key-pad. For instance, pressing the '1' key will return the text '1'. Similarly, pressing the '+' key will return back the text '+'. $&#40;document&#41;.keydown&#40;function &#40;event&#41; &#123; toCharacter&#40;event.keyCode&#41;; &#125;&#41;; &#160; … <a href="http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[The below JQuery snippet returns the character corresponding to the key that was pressed on the QWERTY keyboard or the numeric key-pad.  For instance, pressing the '1' key will return the text '1'.  Similarly, pressing the '+' key will return back the text '+'.


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      toCharacter<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">keyCode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> toCharacter<span style="color: #009900;">&#40;</span>keyCode<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// delta to convert num-pad key codes to QWERTY codes.</span>
    <span style="color: #003366; font-weight: bold;">var</span> numPadToKeyPadDelta <span style="color: #339933;">=</span> <span style="color: #CC0000;">48</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// if a numeric key on the num pad was pressed.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">96</span> <span style="color: #339933;">&amp;&amp;</span> keyCode <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">105</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        keyCode <span style="color: #339933;">=</span> keyCode <span style="color: #339933;">-</span> numPadToKeyPadDelta<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> String.<span style="color: #660066;">fromCharCode</span><span style="color: #009900;">&#40;</span>keyCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">106</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;*&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">107</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;+&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">109</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;-&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">110</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">111</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// the 'Enter' key was pressed</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//TODO: you should change this to interpret the 'Enter' key as needed by your app.</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> String.<span style="color: #660066;">fromCharCode</span><span style="color: #009900;">&#40;</span>keyCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


 
<h3>A little explanation is probably in order...</h3>
<br />

Javascript provides the


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">fromCharCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></pre></div></div>


 method that converts an ASCII character code into it's equivalent text value.  For instance,


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">fromCharCode</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">65</span><span style="color: #008000;">&#41;</span></pre></div></div>


 returns the character 'A'.  The method works great until to try to use it for keys that live on the numeric keypad.  

The ASCII code for the '1' key on the numeric key pad is 97.  If you look this up on the <a href='http://www.asciitable.com/'>ASCII Table</a>, you will find that the ASCII code 97 corresponds to the character 'a' and not the character '1' denoted on the numeric key pad!  The reason for this, as far I can tell, is that the numeric keys simply overload on the existing the ASCII codes.

A little calculation will reveal that subtracting 48 from the ASCII code of the numeric keys will give us the "correct" ASCII code.  For instance, subtracting 97 (which is the ASCII code for the '1' key on the numeric keypad) from 48 gives us 49.  Look up the ASCII code 49 on the <a href='http://www.asciitable.com/'>ASCII Table</a> and you will find that it maps to the character '1'!  

For the keys that correspond to the various symbols such as '+', '-', etc., I am simply returning back the corresponding character.  No mystery there.

Hope this helps!<div class="trackable_sharing"><a href="http://twitter.com/share?url=http%3A%2F%2Fnizarnoorani.com%2Fjquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad&text=JQuery+snippet+to+detect+keystrokes+on+the+numeric+key-pad." style="text-decoration: none; white-space: nowrap;" title="Twitter" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Twitter','http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//twitter.png" alt="Twitter" width="24" height="24"></a> <a href="mailto:?subject=Check out http%3A%2F%2Fnizarnoorani.com%2Fjquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad" style="text-decoration: none; white-space: nowrap;" title="Email" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Email','http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad']); "><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//email.png" alt="Email" width="24" height="24"></a> <a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2Fnizarnoorani.com%2Fjquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad&title=http%3A%2F%2Fnizarnoorani.com%2Fjquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad&ro=false&summary=&source=" style="text-decoration: none; white-space: nowrap;" title="Linkedin" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Linkedin','http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=500,height=350'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//linkedin.png" alt="Linkedin" width="24" height="24"></a> <a href="http://digg.com/submit?partner=addthis&url=http%3A%2F%2Fnizarnoorani.com%2Fjquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad&title=JQuery+snippet+to+detect+keystrokes+on+the+numeric+key-pad.&bodytext=" style="text-decoration: none; white-space: nowrap;" title="Digg" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Digg','http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//digg.png" alt="Digg" width="24" height="24"></a> <a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fnizarnoorani.com%2Fjquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad&title=http%3A%2F%2Fnizarnoorani.com%2Fjquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad" style="text-decoration: none; white-space: nowrap;" title="Stumbleupon" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Stumbleupon','http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=750,height=450'); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//stumbleupon.png" alt="Stumbleupon" width="24" height="24"></a> <a href="http://feeds.feedburner.com/NizarNoorani" style="text-decoration: none; white-space: nowrap;" title="Subscribe" target="_blank" onclick="that=this;_gaq.push(['_trackEvent','SocialSharing','Subscribe','http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad']); _trackableshare_window = window.open(this.href,'share','menubar=0,resizable=1,width=,height='); _trackableshare_window.focus(); return false;"><img align="absmiddle" src="http://nizarnoorani.com/wp-content/uploads/trackableshare//subscribe.png" alt="Subscribe" width="24" height="24"></a> ]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/jquery-snippet-to-detect-keystrokes-on-the-numeric-key-pad/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  nizarnoorani.com/feed ) in 0.99506 seconds, on May 19th, 2012 at 12:08 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 19th, 2012 at 1:08 pm UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  nizarnoorani.com/feed ) in 0.00882 seconds, on May 19th, 2012 at 12:36 pm UTC. -->
