Pages

Friday, July 01, 2011

Selenium with SpecFlow

In addition to the SpecFlow and Selenium Quick Start, here are a few notes on using Selenium in SpecFlow scenarios and step definitions.

Check the files in the Support directory in SpecFlow Examples code (link). There is scaffolding that is very useful if you are using Selenium to simulate user behavior. The SeleniumSupport is linked to @web tag, which should be used for the tests that use the browser (i.e. user acceptance tests). This means that, when scenarios tagged with @web are run, it will trigger events to start and shut down Selenium, and make it available for custom tests in the meantime.

Inheriting from the SeleniumStepsBase makes implementation very simple:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DoerSite.Tests.Support;
using TechTalk.SpecFlow;
using NUnit.Framework;

namespace DoerSite.Tests.SeleniumTests
{
    [TestFixture]
    public class SeleniumStepsSample : SeleniumStepsBase
    {
        [Test]
        public void test()
        {
            this.selenium.Open("/");

            Assert.IsTrue(selenium.IsTextPresent("Welcome!"));
        }
    }
}

This implementation also depends on a couple of settings in the app.config:

  <appSettings>
    <add key="ReuseWebSession" value="true" />
    <add key="AppUrl" value="http://localhost:51598/"/>
  </appSettings>

 

 

No comments: