Adding Resource Files for SpecFlow Test Runs
Sometimes you want to reference other files in your SpecFlow tests. You could be comparing expected to actual data for tables, testing file upload/download, etc.
Â
Add the file to your solution.
Be sure to select
Copy if newer
for theCopy to Output Directory
option. This will ensure that the file is included in the build output.Â
Reference the file using
System.AppDomain.CurrentDomain.BaseDirectory
.[Then(@"the page title matches file contents")] public void ThenThePageTitleMatchesFileContents() { String expectedTitle = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "Resources/GoogleTitle.txt"); Assert.That(driver.Title, Is.EqualTo(expectedTitle)); }
Â
If you get a DirectoryNotFoundException
, double check the path and that you’ve added the files to the build output (see Step 2).
Â