Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1030115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:38:57+00:00 2026-05-16T12:38:57+00:00

Based on this article , I’ve written a custom class which implements the Watin.Core.interfaces.IFindByDefaultFactory,

  • 0

Based on this article, I’ve written a custom class which implements the Watin.Core.interfaces.IFindByDefaultFactory, but I don’t think I’m correctly assigning it to the watin settings, because it is never used.

Basically, Where/when should I assign to the Settings.FindByDefaultFactory? I’ve tried in my test Setup, and the text fixture’s constructor, but neither seem to cause my custom class to be used. The tests still run and work, but I have to use the full asp.net ID’s.

I’m using Watin 2.0.15.928 in VS2008 from nUnit 2.5.2.9222. I am running visual studio as administrator, and tests run sucessfully as long as I don’t rely on my custom find logic.

Here’s what the start of my text fixture looks like, where I set the FindByDefaultFactory

namespace Fundsmith.Web.Main.BrowserTests
{
    [TestFixture]
    class WatinHomepageTests
    {
        private IE _ie;
        [SetUp]
        public void Setup()
        {
            Settings.FindByDefaultFactory = new FindByAspIdFactory();
            _ie = new IE("http://localhost/somepage.aspx");
        }
//etc etc...

And this is what my custom Find By Default factory looks like (simplified), unfortunately, it’s never called.

using System.Text.RegularExpressions;
using WatiN.Core;
using WatiN.Core.Constraints;
using WatiN.Core.Interfaces;

namespace Fundsmith.Web.Main.BrowserTests
{
    public class FindByAspIdFactory : IFindByDefaultFactory
    {
        public Constraint ByDefault(string value)
        {
// This code is never called :(

// My custom find by id code to cope with asp.net webforms ids...
            return Find.ById(value);
        }

        public Constraint ByDefault(Regex value)
        {
            return Find.ById(value);
        }
    }
}

Edit: Extra information after the fact.

Based on me fuguring this out, (see answer below), It turns out that the way I was consuming Watin to find the elements was wrong. I was explicitly calling Find.ById, rather than letting the default action occur. So I’d reassigned the default but was then failing to use it!

[Test]
public void StepOneFromHomepageShouldRedirectToStepTwo()
{
    _ie.TextField(Find.ById("textBoxId")).TypeText("100");
        //Other test stuff...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:38:58+00:00Added an answer on May 16, 2026 at 12:38 pm

    Right, I’ve figured this one out, and it was me being an idiot and explicitly calling the Find.ById method, rather than letting the default action occur. It seems the test setup is a fine place to set the FindByDefaultFactory.

    ie, I was doing this (wrong):

        [Test]
        public void StepOneFromHomepageShouldRedirectToStepTwo()
        {
            _ie.TextField(Find.ById("textBoxId")).TypeText("100");
                //Other test stuff...
        }
    

    When I should have been simply doing this. (Without the explicit “Find.ById”)

        [Test]
        public void StepOneFromHomepageShouldRedirectToStepTwo()
        {
            _ie.TextField("textBoxId").TypeText("100");
                //Other test stuff...
        }
    

    Not only was this me being stupid, but I didn’t include this in my original question, so it would have been impossible for anyone else to figure it out for certain. Double slaps for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.