Framework Structure

Directory Structure

    1. Open up Visual Studio Code in the root of your project from Terminal
    2. In the Explorer pane in Visual Studio Code, right-click on the project name (e.g. ProductAutomation) and select ‘New Folder’
      • Name the folder ‘Features’
  1. Repeat the above steps and add the following top-level folders…
    • Pages
    • Steps
    • Utils
  2. Add the following sub-folders to the ‘Utils’ directory…
    • Extensions
    • Hooks
    • Selenium

Initial Files in each Directory

Features Folder

  1. Right-click the ‘Features’ folder and select ‘New File’
  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 class…
    • BasePage.cs

Steps Folder

The steps folder/namespace will contain all our step definition classes, which will contain our step definitions / glue which links our steps in our test scenarios to the c# methods which perform different actions.

When it comes to grouping our step definitions, it is good practice to have a Step Definition class file for each major domain object we are trying to test.

For example, in this blog series, we will mainly be testing that a user can search for “Reddit” on DuckDuckGo and then navigate to Reddit by selecting the appropriate search result.

So in this case, we could have the following Step Definition files…

  1. Right-click the ‘Steps’ folder, select ‘New File’ and add the following classes to the package (the ‘Steps’ folder will contain all our step definitions, which acts as the glue that connects our BDD/Gherkin language scenarios in our Feature files, to our test methods in our C# classes.  Please see https://cucumber.io/docs/gherkin/step-organization/ for more information)
    • BaseSteps.cs
      • this class contains all the step definitions for your base scenarios and steps that apply across multiple domain objects
    • SearchSteps.cs
      • this class contains all the step definitions for steps that perform actions around searching on DuckDuckGo
    • RedditSteps.cs
      • this class contains all the step definitions for steps that involve Reddit

Utils Folder

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)
    • WebDriverExtensions.cs
    • WebElementExtensions.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.)
    • SpecFlowHooks.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
    • Settings.cs

GitIgnore

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

  1. Create a file called .gitignore in the root of the framework
    1. Click the Solution file then click the new File button/icon for the very top folder you made to store everything
  2. Add the following into a blank file which is taken from https://github.com/SeleniumHQ/selenium/blob/master/.gitignore…
  3. Save the file as ‘.gitignore’ in your project root (where the .sln file exists)

Downloading the Drivers

  1. Create a folder in the root of the whole project called ‘_drivers’

Chrome

  1. Download the appropriate ChromeDriver for your Chrome browser from https://chromedriver.chromium.org/downloads
  2. Place the downloaded driver in the ‘_drivers’ folder
Liked it? Take a second to support Thomas on Patreon!

Previous Article

Next Article

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.