Framework Structure

Directory Structure

  1. In the Solution Explorer, right-click on the project name and select ‘Add’ –> ‘New Folder’
    • Name the folder ‘Features’
  2. Repeat the above steps and add the following top-level folders…
    • Pages
    • Steps
    • Utils
  3. Add the following sub-folders to the ‘Utils’ directory…
    • Drivers
    • Extensions
    • Helpers
    • Hooks
    • Selenium

Initial Files in each Directory

Features Folder

  1. Right-click the ‘Features’ folder and select ‘Add’ –> ‘New Item’
  2. In the window that appears, select ‘SpecFlow Feature File’
  3. Add the following ‘Feature’ file…
    • BaseScenarios.feature

Pages Folder

  1. Right-click the ‘Pages’ folder and select ‘Add’ –> ‘New Class’
  2. Add the following classes…
    • Page.cs
    • BasePage.cs

Steps Folder

  1. Right-click the ‘Steps’ folder and select ‘Add’ –> ‘New Item’
  2. In the window that appears, select ‘SpecFlow Step Definition’
  3. Add the following step definition class files…
    • BaseScenariosSteps.cs
      • this class contains all the step definitions for your base scenarios
    • BaseSteps.cs
      • this is simply an empty placeholder class which inherits from the ‘Page’ class, to follow POM principles
    • DynamicTableSteps.cs
      • this class contains all the step definitions for scenario lines which contain dynamic data tables
    • NonDynamicTableSteps.cs
      • this class contains all the step definitions for scenario lines which contain non-dynamic data tables
    • ReturnClickSteps.cs
      • this class contains all the step definitions for scenario lines / test methods which return a new Page Object when a web element is clicked on
    • SendKeysSteps.cs
      • this class contains all the step definitions for scenario lines / test methods which sends keys / a string to a web element
    • ValidationSteps.cs
      • this class contains all the step definitions for our test assertions
    • VoidClickSteps.cs
      • this class contains all the step definitions for scenario lines / test methods that do not return anything (void) when a web element is clicked on

Utils Folder

Drivers subfolder

  1. Right-click the ‘Drivers’ subfolder and select ‘Add’ –> ‘New Class’
  2. Add the following class files…
    • ChromeWebDriver.cs
    • FirefoxWebDriver.cs

Extensions subfolder

  1. Right-click the ‘Extensions’ subfolder, select ‘Add’ –> ‘New Class’ and add the following classes to the namespace (the ‘Extensions’ namespace will contain class files for all extension methods we can use with our existing functionality / test methods)
    • GeneralExtensions.cs
    • JavascriptExtensions.cs
    • JqueryExtensions.cs
    • JquerySelectorExtensions.cs
    • WebDriverExtensions.cs
    • WebElementExtensions.cs

Helpers subfolder

  1. Right-click the ‘Helpers’ subfolder, select ‘Add’ –> ‘New Class’ and add the following classes to the namespace(the ‘Helpers’ namespace will contain class files for all our ‘Helpers’ methods to our existing functionality)
    • GeneralHelpers.cs
    • JavascriptHelpers.cs

Hooks subfolder

  1. Right-click the ‘Hooks’ subfolder, select ‘Add’ –> ‘New Class’ and add the following classes to the namespace (the ‘Hooks’ namespace will contain classes for all the different hooks we can run before and/or after test runs/suites/scenarios etc.)
    • FeatureHooks.cs
    • ScenarioHooks.cs
    • ScenarioBlockHooks.cs
    • StepHooks.cs
    • TestRunHooks.cs

Selenium subfolder

  1. Right-click the ‘Selenium’ subfolder, select ‘Add’ –> ‘New Class’ and add the following classes to the namespace (the ‘Selenium’ namespace will contain our core WebDriver setup and DriverController instance, as well as a Settings class where we can list public static variables to be used in our project)
    • Driver.cs
    • DriverController.cs
    • Settings.cs

GitIgnore

We will now add a .gitignore file to ignore certain files and packages if/when we push to a remote repository.

Good practice is to have all of our NuGet packages listed in the ‘packages.config’ file and then git ignore the actual NuGet packages folders. When the project is cloned from the remote repository, NuGet Package Restore will be run when we build the solution and will restore all the packages that we need for us.

Additionally, we will git ignore the SpecFlow designer code.  All our SpecFlow Feature files auto-generate designer code, which we can also exclude from the remote repository. When the project is cloned from the remote repository, we can right-click on the project in the Solution Explorer (in Visual Studio) and select ‘Regenerate Feature Files’ 🙂

Finally, we will ignore Visual Studio specific folders that are not needed.

  1. Open up a text/file editor program like Notepad++ or Sublime Text (google, download and install if need be)
  2. Add the following into a blank file…
  3. Save the file as ‘.gitignore’ in your project root (where the .sln file exists)
Liked it? Take a second to support Thomas on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.