9

We have an old asp.net application that has no unit tests, integration tests, component tests or UI/functional tests - surprise!

Now, we'd like to introduce some automated system testing that tests the functionality so that when something breaks in the app we immediately get notified!

For example, the user registration form where user can enter username and email address and register in the system.

It's too late/expensive to introduce unit tests (as the current design is not unit testable) so the most important thing now is writing Automated System Tests.

For example, we'd like to write a test in C# which opens the browser, enters the data to the text boxes, clicks on the Register button then our test checks whether the data is inserted into the database and whether a verification email is sent and at the end whether a proper message is shown to the user (of course this is only the main scenarios and there would be numerous special cases). Basically not testing isolated units but testing whether the whole process works!

So, what tool could I use to help me write such test and automating it?

What approach would you recommend to use?

I had a look at Selenium and Fitnesse but they don't seem to allow me write C# code to test database, etc. I looked at the SoapUI/LoadUI same issue. WatiN could possibly be used, not sure. any thoughts/recommendations are very much appreciated.

Hope the question is clear.

Many thanks,

4
  • seleniumhq.org is the de facto tool or if you have Visual Studio Ultimate, I believe that version has some sort of ability to do that. Commented Jan 24, 2012 at 17:07
  • the visual studio have "test" program included, and do the thinks that you describe here. Do you have try it ? Commented Jan 24, 2012 at 17:12
  • @Joe using Selenium you can write c# code? we have Professional edition of VS only. Commented Jan 24, 2012 at 17:17
  • yeah but that's only part of what I'm after. LoadUI/SoapUI would also do that. I'd need to write a test which also checks the database for example. The whole components which are involved in the process, not only the UI changes. Commented Jan 24, 2012 at 17:39

5 Answers 5

9

Selenium absolutely does allow you to write C# code for system testing. First you would have a method to interact with the website, a second method to verify the database is correct. All within a single test app/class.

For the web interaction, you would use a WebDriver (taken from the Selenium API doc). Here's some example code of IWebDriver's interface. It interacts with google, but you can modify this to interact with your website.

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;

class GoogleSuggest
{
    static void Main(string[] args)
    {
        IWebDriver driver = new FirefoxDriver();
        driver.Navigate().GoToUrl("http://www.google.com/");
        IWebElement query = driver.FindElement(By.Name("q"));
        query.SendKeys("Cheese");
        System.Console.WriteLine("Page title is: " + driver.Title);
        driver.Quit();
    }
}

Then you would just implement another method that verifies the database entries are correct, using something like LinqToSql or other C# database API.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks, could you also record/replay user activity on the page with Selenium?
I've never used WatiN so I cannot comment on its capabilities. As far as record and replay, yes you can use Selenium IDE (Firefox Add-on) to click through your web ui and the IDE will record your actions in Selenese. Then you can export that to C# code easily. I've never done this myself, but according to their docs it is easy.
Note that the generated code assumes you are using NUnit in C# which you don't necessarily need. You just need the IWebDriver interactions. Depends on how formal and sophisticated you want this to be.
2

If you have Visual Studio Ultimate, perhaps a Coded UI Test is what you're looking for? http://msdn.microsoft.com/en-us/library/dd286681.aspx

1 Comment

Coded UI Tests are also available for Visual Studio 2010 Premium.
1

Use CodedUI or Selenium Web driver

1 Comment

I think you will get good idea from here-- blog.gfader.com/2010/02/…
1

You could also look to Telerik's Test Studio as a solution for your testing needs. (Disclosure: I work for Telerik as their Test Studio Evangelist.)

Test Studio lets you easily create extremely maintainable functional and performance tests.

You can also easily add steps or tests in C# (or VB.NET) to handle things like test fixture setup/teardown, or to deal with test oracle situations like you mention. (Checking the database to ensure a record is properly saved, tying in something like nDumbster for e-mail validation, etc.)

Comments

1

Selenium Webdriver can be added as package to C# project in Visual studio express IDE and then adding nUnit package one can write test cases. Below are the few links that can help you get kickstarted with selenium webdriver Automated test cases

On how to setup the IDE (VS express), nUnit and selenium refer How to setup C#,nUnit and selenium client drivers on VSExpress for Automated tests

On Creating simple script that launches a browser does few steps refer Creating Basic Selenium web driver test case using Nunit and C#

On how to Load the same webpage on a number of different browsers I suggest referring How to invoke locally different types of browser driver using selenium and c#

On Loading the same webpage on a number of virtual machines for this, you need to use Remote webdriver instead of normal webdriver. Also with remote webdriver, you can launch different types of browser. Refer this webpage How to invoke/run different type of web driver browser using remote webdriver in C#

To take snapshot on different browser you can refer the link Capturing screen shots using remote/local webdriver in C#/Selenium webdriver

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.