Functional tests for a web app repeating the same code My problem/concern is that I am trying to remove duplicate code from my functional tests without breaking the Page Object Pattern that I am following. 

If you look at the code below, you will notice that 4 lines are constantly repeated in my tests, breaking the DRY principle - they are marked with a "todo" comment. But the problem is that the methods belong to 2 different Page Objects/classes. Therefore, I don't know how to condense this code because it doesn't belong in either page since it uses 2 different pages.

I'm following the Single Responsibility Principle that the Page Object class actually represents a single web page through my code, essentially doing 1 thing. I don't want to break this principle in order to condense my code. But I also don't want to maintain this duplicate code throughout a bunch of my tests.

The problem my code solves is that they are tests written against a GUI to exercise the functionality under test.

using Automation.Pages;
using NUnit.Framework;

namespace Automation.Tests
{
[TestFixture, Author("nikolay"), Category("LL"), Property("FunctionalityTested","ShortTextPopUp")]
class ShortTextPopupTests : BaseTest
{
    [Test]
    [Retry(2)]
    [Description("Validate that the pop up can open and close when it is clicked.")]
    public void GivenCorrectItemIsOpened_WhenTogglingPopup_ThenPopupOpensAndCloses()
    {
        //todo these 4 lines are repeated everywhere for the setup of this test
        var adminLoginPage = new ENAEPAdminLoginPage(Driver);
        adminLoginPage.GoToAndLoginWithOperationalBookletSupervisor();
        var adminResetPage = new AdminResetPage(Driver);
        var studentAssessmentPage = adminResetPage.GoToSpecificBookletLocation(BookletLocations.ShortTextPopup);

        studentAssessmentPage.ShortTextPopup.OpenPopUp();
        studentAssessmentPage.ShortTextPopup.ClosePopUp();
        Assert.IsFalse(studentAssessmentPage.ShortTextPopup.IsPopUpOpen(), "The pop up did not close after trying to close the pop up");
    }

    [Test]
    [Retry(2)]
    [Description("Validate that opening a pop up, clicking next, coming back to a page, closes that opened pop up")]
    public void NavigationToDifferentPageClosesPopup()
    {
        //todo these 4 lines are repeated everywhere for the setup of this test
        var adminLoginPage = new ENAEPAdminLoginPage(Driver);
        adminLoginPage.GoToAndLoginWithOperationalBookletSupervisor();
        var adminResetPage = new AdminResetPage(Driver);
        var studentAssessmentPage = adminResetPage.GoToSpecificBookletLocation(BookletLocations.ShortTextPopup);

        studentAssessmentPage.ShortTextPopup.OpenPopUp();

        studentAssessmentPage.ENAEPToolBar.ClickNextButton();
        studentAssessmentPage.ENAEPToolBar.ClickBackButton();
        Assert.IsFalse(studentAssessmentPage.ShortTextPopup.IsPopUpOpen(), "The pop up did not close after leaving and coming back to the page.");
    }

    [Test]
    [Retry(2)]
    [Description("Opening a short text pop up and then clicking on other things on the page should not close the pop up.")]
    [Property("TCID", "35458")]
    public void ClickingItemsOnScreenShouldNotClosePopUps()
    {
        //todo these 4 lines are repeated everywhere for the setup of this test
        var adminLoginPage = new ENAEPAdminLoginPage(Driver);
        adminLoginPage.GoToAndLoginWithOperationalBookletSupervisor();
        var adminResetPage = new AdminResetPage(Driver);
        var studentAssessmentPage = adminResetPage.GoToSpecificBookletLocation(BookletLocations.ShortTextPopup);

        studentAssessmentPage.ShortTextPopup.OpenPopUp();
        studentAssessmentPage.ClickRandomPlacesOnPage();
        Assert.IsTrue(studentAssessmentPage.ShortTextPopup.IsPopUpOpen(), "The popup did not stay open after clicking in random places in the assessment.");
    }
}


}
Move your 4 lines into a method with a [TestFixtureSetUp] Attribute. This will run everytime a test is run.

See here: http://www.nunit.org/index.php?p=fixtureSetup&amp;r=2.2.10

For example:

class ShortTextPopupTests : BaseTest
{
    private ENAEPAdminLoginPage adminLoginPage;
    private AdminResetPage adminResetPage;
    private AppropriateType studentAssessmentPage;

    [TestFixtureSetUp]
    public void SetupFixture()
    {
        adminLoginPage = new ENAEPAdminLoginPage(Driver);
        adminLoginPage.GoToAndLoginWithOperationalBookletSupervisor();
        adminResetPage = new AdminResetPage(Driver);
        studentAssessmentPage = adminResetPage.GoToSpecificBookletLocation(BookletLocations.ShortTextPopup);
        studentAssessmentPage.ShortTextPopup.OpenPopUp();
    }

    [Test]
    [Retry(2)]
    [Description("Validate that the pop up can open and close when it is clicked.")]
    public void GivenCorrectItemIsOpened_WhenTogglingPopup_ThenPopupOpensAndCloses()
    {
        studentAssessmentPage.ShortTextPopup.ClosePopUp();
        Assert.IsFalse(studentAssessmentPage.ShortTextPopup.IsPopUpOpen(), "The pop up did not close after trying to close the pop up");
    }

    [Test]
    [Retry(2)]
    [Description("Validate that opening a pop up, clicking next, coming back to a page, closes that opened pop up")]
    public void NavigationToDifferentPageClosesPopup()
    {
        studentAssessmentPage.ENAEPToolBar.ClickNextButton();
        studentAssessmentPage.ENAEPToolBar.ClickBackButton();
        Assert.IsFalse(studentAssessmentPage.ShortTextPopup.IsPopUpOpen(), "The pop up did not close after leaving and coming back to the page.");
    }

    [Test]
    [Retry(2)]
    [Description("Opening a short text pop up and then clicking on other things on the page should not close the pop up.")]
    [Property("TCID", "35458")]
    public void ClickingItemsOnScreenShouldNotClosePopUps()
    {
        studentAssessmentPage.ClickRandomPlacesOnPage();
        Assert.IsTrue(studentAssessmentPage.ShortTextPopup.IsPopUpOpen(), "The popup did not stay open after clicking in random places in the assessment.");
    }
}