- 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…
- Add the following sub-folders to the ‘Utils’ directory…
Initial Files in each Directory
- Right-click the ‘Features’ folder and select ‘New File’
- In the window that appears, select ‘SpecFlow Feature File’
- Add the following ‘Feature’ file…
- Right-click the ‘Pages’ folder and select ‘Add’ –> ‘New Class’
- Add the following class…
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)
- this class contains all the step definitions for your base scenarios and steps that apply across multiple domain objects
- this class contains all the step definitions for steps that perform actions around searching on DuckDuckGo
- this class contains all the step definitions for steps that involve Reddit
- 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)
- 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.)
- 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)
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…
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216# 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 filesipch/*.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-inDocProject/buildhelp/DocProject/Help/*.HxTDocProject/Help/*.HxCDocProject/Help/*.hhcDocProject/Help/*.hhkDocProject/Help/*.hhpDocProject/Help/Html2DocProject/Help/html# Click-Once directorypublish/# Publish Web Output*.Publish.xml# Windows Azure Build Outputcsx*.build.csdef# Windows Store app package directoryAppPackages/# Others*.CacheClientBin/[Ss]tyle[Cc]op.*~$**~*.dbmdl*.[Pp]ublish.xml*.pfx*.publishsettingsmodulesbin/tempbin/# EPiServer Site file (VPP)AppData/# RIA/Silverlight projectsGenerated_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*.XMLUpgradeLog*.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 filesGeneratedArtifacts/_Pvt_Extensions/ModelManifest.xml# =========================# Windows detritus# =========================# Windows image file cachesThumbs.dbehthumbs.db# Folder config fileDesktop.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 stuffproject.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’
- Download the appropriate ChromeDriver for your Chrome browser from https://chromedriver.chromium.org/downloads
- Place the downloaded driver in the ‘_drivers’ folder