Search code examples
c#seleniumselenium-webdriverfluentautomation

How to organize tests and PageObject classes with FluentAutomation and MSTest (Cannot resolve symbol "I" error)


I am trying to run the example in the documentation here.

I am using Visual Studio with MSTest, so I modified the code a little bit and it looks like this now:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAutomation;
using FluentAutomation.Interfaces;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace UnitTestProject1
{
    public class BingSearchPage : PageObject
    {
        public BingSearchPage(FluentTest test)
            : base(test)
    {
        Url = "http://bing.com/";
        At = () => I.Expect.Exists(SearchInput); //Documentation says "At = () =>; I.Expect.Exists(SearchInput);" but I think that's a typo
    }

        public BingSearchResultsPage Search(string searchText)
        {
            I.Enter(searchText).In(SearchInput);
            I.Press("{ENTER}");
            return this.Switch();
        }

        private const string SearchInput = "input[title='Enter your search term']";
    }

    public class BingSearchResultsPage : PageObject
    {
        public BingSearchResultsPage(FluentTest test)
            : base(test)
        {
            At = () => I.Expect.Exists(SearchResultsContainer);
        }

        public BingSearchResultsPage FindResultUrl(string url)
        {
            I.Expect.Exists(string.Format(ResultUrlLink, url));
            return this;
        }

        private const string SearchResultsContainer = "#b_results";
        private const string ResultUrlLink = "a[href='{0}']";
    }

    [TestClass]
    public class UnitTest1 : FluentTest
    {
        public UnitTest1()
        {
            SeleniumWebDriver.Bootstrap(SeleniumWebDriver.Browser.Chrome);
        }

        [TestMethod]
        public void SearchForFluentAutomation()
        {
            new BingSearchPage(this)
                .Go()
                .Search("FluentAutomation")
                .FindResultUrl("http://fluent.stirno.com/blog/FluentAutomation-scriptcs/");
        }
    }
}

I get errors like:

Error 1 'FluentAutomation.PageObject' does not contain a constructor that takes 1 arguments C:\Users\Shitij\Documents\Visual Studio 2013\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs 13 15 UnitTestProject1

Error 2 The name 'I' does not exist in the current context C:\Users\Shitij\Documents\Visual Studio 2013\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs 16 20 UnitTestProject1

Error 3 'UnitTestProject1.BingSearchPage' does not contain a definition for 'Switch' and no extension method 'Switch' accepting a first argument of type 'UnitTestProject1.BingSearchPage' could be found (are you missing a using directive or an assembly reference?) C:\Users\Shitij\Documents\Visual Studio 2013\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs 23 25 UnitTestProject1

Feels like a stupid question, but I am stuck on it. Any idea what I am doing wrong? The property "I" seems to be in FluentTest class, so how is the documentation using that in classes derived from PageObject?


Solution

  • Theres an issue with the docs on the site atm. Really need to get it fixed. The generic bits are missing!

    change PageObject to PageObject<BingSearchResultsPage> and I should resolve.