1

I have a test automation project I am working on that requires UI testing in the browser. For this project I have setup a .NET Core 3.1 project with the following packages:

<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="16.8.3" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="87.0.4280.8800" />
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.27.0" />
<PackageReference Include="Selenium.WebDriver.IEDriver" Version="3.150.1.2" />
<PackageReference Include="SpecFlow" Version="3.5.14" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.5.14" />
<PackageReference Include="SpecRun.SpecFlow" Version="3.5.22" />

When I try to run any of my tests I get the following error:

The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html.

However the chromedriver is included in the Selenium.WebDriver.ChromeDriver package. It should be copied to the bin folder during the build process, so I checked the folder and it is present.

So I figured the current directory is not the bin folder but some other folder, so I changed my code and passed the current directory as an argument to the chromedriver like so:

...
var driver new ChromeDriver(System.IO.Directory.GetCurrentDirectory());
...

Now I get the following error:

The file C:\path\to\project\TestResults\chromedriver.exe does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html

Which indicates that the current directory is not the bin folder but the output folder of my test results.

How do I change this behaviour so that it will automatically look in the correct folder?

BTW: I have found the following solution to a similar problem. However this solution relies on hardcoding the path, either the full path/ driver version or platform/configuration. This is not an option as it is my intent to use the same code on different environments.

Sam Beard
  • 50
  • 7

1 Answers1

1

You are using the SpecFlow+ Runner, which per default uses process isolation for separating the threads. Because of this, the working directory is not the output directory.

You have two options:

  1. Getting the folder via API from SpecFlow+ Runner

We have an API to get the output folder. Get an instance of TestRunContext via context injection and use the TestDirectory property (https://docs.specflow.org/projects/specflow-runner/en/latest/Usage/SpecFlow-Runner-APIs.html#string-testdirectory-get).

  1. Switch to shared appdomain

I would only do this, if you don't need an isolation between your test threads.

Put in your Default.srProfile this

<Environment testThreadIsolation="SharedAppDomain" />

The whole file should look like this: https://github.com/SpecFlowOSS/Streaming-Projects/blob/main/CommunityContentSubmissionPage/CommunityContentSubmissionPage.Specs/Default.srprofile


Full disclosure: I am the community manager of SpecFlow and SpecFlow+

Andreas Willich
  • 5,665
  • 3
  • 15
  • 22
  • For option one, do you mean the TestRunContext class? – Sam Beard Jan 19 '21 at 14:25
  • Yes. I had the name remembered incorrectly. – Andreas Willich Jan 19 '21 at 14:30
  • I have tried solution n. 1 and it works correctly. I had already written a fairly hacky work around for retrieving the directory but this is definitely a better solution. I will mark it as solved. I do however not fully understand the concept of process isolation in solution n. 2, and therefore can not decide whether solution n. 2 would be a suitable solution for my case. Do you have a resource on process isolation (with specflow) which you could possibly incorporate into the answer? thanks again. – Sam Beard Jan 19 '21 at 14:46
  • Sure, I can do that. Documentation about the different isolation modes are here: https://docs.specflow.org/projects/specflow-runner/en/latest/Usage/Parallel-Execution-Features.html I will add this information to the answer. – Andreas Willich Jan 19 '21 at 14:48