Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I'm working on setting up a SpecFlow project to test a portal. Thus far I've haven't had issues writing some "hello world" features and steps. My question is as the testing project grows, what is the best way to have the features run against a set of browsers?

Here are some solutions I've been able to come up with or see examples of online:

  • The browsers can be passed in as Examples for each Scenerio (Source), but this seems like it would bloat the Scenerio.

  • I looked into Tags and BeforeScenerio hooks, but that doesn't allow multiple browsers to be tested as the steps wouldn't be executed against each tag.

  • Setting the driver set in a static helper and depending which you want to run, the code can be commented/uncommented (Source). I probably wouldn't have it be commented out code, but abstract it into some Setting/Factory class. It would still be a code change though.

  • Following with the option above, the driver could be selected on a build variable (#if IETESTING, etc), but I thought I once came across some statements claiming that these could be considered anti-patterns.

My final thoughts would be that the feature/gherkin files should not change to test different browsers for the great majority of cases as most features shouldn't have a browser requirement (exceptions could be newer HTML5 APIs & their fallbacks). I believe if they were controlled by some configuration that could be applied after compiling would preferable, but I'm unclear how best to accomplish this.

Hello World

share|improve this question

2 Answers 2

I struggled with this and what I ended up doing at the moment was generating different tests for different browsers, as much as I wanted repeatability I did not see this as doable within the current framework and browser functionality. The largest problem you will find with cross-browser support is going to be where you have to deal with buttons, click and keys.enter do not work consistently across IE, Chrome or Firefox. Finding page elements will also be different as CSS is handled differently across the browsers as well.

I have looked occasionally for an option you have noted but I personally find that the exceptions I would need to make for functionality as well as browser types would make my test code too bloated so I use SpecFlow to limit my steps and break off to different sections for the browser specific handling when necessary. To me that manages the duplication I need to do and still gets me effective testing.

share|improve this answer

It appears that NUnit http://www.nunit.org/index.php?p=testFixture&r=2.5 now supports parameterized test fixtures. This may allow you to create a test that will do what you need. This SO answer has a similar question for NUnit selenium tests.

http://stackoverflow.com/questions/5028926/run-selenium-tests-in-multiple-browsers-one-after-another-from-c-sharp-nunit

You might see if you modify your SpecFlowFeature1Steps.cs and run it to see what happens. Don't forget to reference the other browsers in the using.

[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
    private IWebDriver driver;

    [SetUp]
    public void CreateDriver () {
        this.driver = new TWebDriver();
    }

I would be sure to ask yourself though if Specflow is the appropriate place for multi browser tests.

share|improve this answer
    
This was my solution before Specflow, but since the actual NUnit TestFixture are generated by Specflow I haven't found a way to integrate this into the solution. –  Paul DelRe Feb 26 '13 at 13:39
    
I would be interested in some expansion on your final comment on the proper place for multi browser testing. –  Paul DelRe Feb 26 '13 at 13:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.