Click here to Skip to main content
13,086,228 members (73,233 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 12 Apr 2012

Writing Integration Tests for ASP.NET with Selenium – Part 1

, 12 Apr 2012
Rate this:
Please Sign up or sign in to vote.
This is the first in a series of posts on writing integration tests for ASP.NET using the Selenium web application testing system.

This is the first in a series of posts on writing integration tests for ASP.NET using the Selenium web application testing system.

In this post, I explain what it is, why use it and how to setup and configure it. In the next subsequent posts, I’ll do a code walk-through and also share some advanced scenarios.

What is Selenium?

The best description of Selenium is probably the one mentioned on their website:

“Selenium automates browsers. That’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.”

Why Use Selenium?

There are other integration testing web frameworks out there such as WaitN or the Lightweight Test Automation Framework for testing ASP .NET web apps. So, why use Selenium? Here are the main reasons why I picked it:

  1. 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 QAs. You can even use a combination of recorded test scenarios and C# test cases to integration test your application.
  2. 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’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.
  3. 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.
  4. Finally, the test recorder is a small Firefox plug in and integrates real nice with Firefox.

Convinced? Awesome! Let’s move on to setting up Selenium…

Initial Setup

There are three parts to setting up Selenium:

Okay, at this point, we should be all set with Selenium. Verify the following:

  1. Installing the Selenium IDE: A Firefox plug in that allows you to manually record test scenarios. Find and download the Selenium IDE plug in from the Selenium Downloads 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.
  2. Installing the Selenium stand-alone server: Accepts commands from your C# test cases and automates the browser. Find and download the Selenium Server from the Selenium Downloads section. It’s a JAR file so make sure you have the JDK (Java Development Toolkit) installed. If not, then download the JDK @ Java Downloads.
  3. Grabbing the ThoughtWorks Selenium DLL: The missing link between Selenium and C#. It enables C# test-cases to talk to Selenium. Find and download the C# Selenium Client Driver from the Selenium Downloads section. Upon extracting the zip file, you’ll find a bunch of the DLLs in there. Ignore everything and just copy/paste the ThoughtWorks.Selenium.Core.dll file into wherever your project references external DLLs from. That’s all we need! The rest of the DLLs provide a slightly different API that’s supposed to be bit easier to work with. But I didn’t find them very useful and more importantly, I had trouble running my tests with them. Kept getting errors. Anyways, I’d recommend just sticking with the ThoughtWorks DLL. The subsequent posts on this topic that I will be writing will use the ThoughtWorks API.
    REM start-selenium-server.bat
    cd .
    java -jar selenium-server-standalone-2.20.0.jar
    • 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, 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 page when you click the Play button. Hopefully, it worked. If not, call me. I’ll help you out and I only charge a $150/hr. Just kidding. If it doesn’t work, then try re-installing the plug in, I guess. :)
    • You are able to start the Selenium server: Moveover, the Selenium JAR file that you download in step 2 to a folder of your choosing. Open up the command prompt, navigate to the folder where you have placed the JAR file and run the following: java -jar selenium-server-standalone-2.20.0.jar. That should start the Selenium stand-alone server. Press Ctrl+C to quit. For feasibility, I placed the JAR file in the same directory as my unit-tests project. I then created a BAT file that I just double-click to start the server. Here is what the BAT file looks like:
    • You are able to write and run C# test-cases using the ThoughtWorks DLL for Selenium – This is what I’ll go over in my next post on Selenium. Check back soon…


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nizar Noorani
Software Developer (Senior) NCube, Inc.
United States United States
Nizar Noorani is an independent software consultant. He provides services in the areas of web applications and systems architecture, analysis, design and development. Although proficient in a variety of technologies, he specializes in the .NET technology. He can be reached at

You may also be interested in...


Comments and Discussions

QuestionWhy not to use Visual studio cided ui tests? They do the same Pin
Dennis_Nerush12-Apr-12 9:49
memberDennis_Nerush12-Apr-12 9:49 
AnswerRe: Why not to use Visual studio cided ui tests? They do the same Pin
stooboo12-Apr-12 12:40
memberstooboo12-Apr-12 12:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 12 Apr 2012
Article Copyright 2012 by Nizar Noorani
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid