Table of Contents
Framework Structure
Directory Structure
-
- Open up Visual Studio Code in the root of your project from Terminal
- 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’
- Repeat the above steps and add the following top-level folders…
- Pages
- Steps
- Utils
- Add the following sub-folders to the ‘Utils’ directory…
- Extensions
- Hooks
- Selenium
Initial Files in each Directory
Features Folder
- Right-click the ‘Features’ folder and select ‘New File’
- In the window that appears, select ‘SpecFlow Feature File’
- Add the following ‘Feature’ file…
- BaseScenarios.feature
Pages Folder
- Right-click the ‘Pages’ folder and select ‘Add’ –> ‘New Class’
- 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…
- 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
- BaseSteps.cs
Utils Folder
Extensions subfolder
- 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
- 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
- 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.
- Create a file called .gitignore in the root of the framework
- Click the Solution file then click the new File button/icon for the very top folder you made to store everything
- Add the following into a blank file which is taken from https://github.com/SeleniumHQ/selenium/blob/master/.gitignore…
# User-specific files *.suo *.user *.sln.docstates # Build results [Dd]ebug/ [Rr]elease/ x64/ [Bb]in/ [Oo]bj/ # build folder is nowadays used for build scripts and should not be ignored #build/ # NuGet Packages *.nupkg # The packages folder can be ignored because of Package Restore **/packages/* # except build/, which is used as an MSBuild target. !**/packages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/packages/repositories.config # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* *_i.c *_p.c *.ilk *.meta *.obj *.pch *.pdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *.log *.vspscc *.vssscc .builds *.pidb *.log *.scc # OS generated files # .DS_Store* Icon? # Visual C++ cache files ipch/ *.aps *.ncb *.opensdf *.sdf *.cachefile # Visual Studio profiler *.psess *.vsp *.vspx # Guidance Automation Toolkit *.gpState # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover # NCrunch *.ncrunch* .*crunch*.local.xml # Installshield output folder [Ee]xpress/ # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish/ # Publish Web Output *.Publish.xml # Windows Azure Build Output csx *.build.csdef # Windows Store app package directory AppPackages/ # Others *.Cache ClientBin/ [Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.[Pp]ublish.xml *.pfx *.publishsettings modulesbin/ tempbin/ # EPiServer Site file (VPP) AppData/ # RIA/Silverlight projects Generated_Code/ # Backup & report files from converting an old project file to a newer # Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm # vim *.txt~ *.swp *.swo # Temp files when opening LibreOffice on ubuntu .~lock.* # svn .svn # CVS - Source Control **/CVS/ # Remainings from resolving conflicts in Source Control *.orig # SQL Server files **/App_Data/*.mdf **/App_Data/*.ldf **/App_Data/*.sdf #LightSwitch generated files GeneratedArtifacts/ _Pvt_Extensions/ ModelManifest.xml # ========================= # Windows detritus # ========================= # Windows image file caches Thumbs.db ehthumbs.db # Folder config file Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ # Mac desktop service store files .DS_Store # SASS Compiler cache .sass-cache # Visual Studio 2014 CTP **/*.sln.ide # Visual Studio temp something .vs/ # dotnet stuff project.lock.json # VS 2015+ *.vc.vc.opendb *.vc.db # Rider .idea/ # Visual Studio Code .vscode/ # Output folder used by Webpack or other FE stuff **/node_modules/* **/wwwroot/* # SpecFlow specific *.feature.cs *.feature.xlsx.* *.Specs_*.html ##### # End of core ignore list, below put you custom 'per project' settings (patterns or path) #####
- Save the file as ‘.gitignore’ in your project root (where the .sln file exists)
Downloading the Drivers
- Create a folder in the root of the whole project called ‘_drivers’
Chrome
- Download the appropriate ChromeDriver for your Chrome browser from https://chromedriver.chromium.org/downloads
- Place the downloaded driver in the ‘_drivers’ folder