Reputation: 100
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.
Upvotes: 1
Views: 890
Reputation: 5835
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:
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).
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+
Upvotes: 1