While trying to running a TeamMentor UnitTest in Chrome I got this error:
Using the trick shown in Coding Firefox in C# in real-time using Selenium's Firefox driver, let’s run this in under firefox to see where this chrome dll should be (i.e. I’m looking for what is the ‘current directory’)
Here is what is in this location:
let’s take a look at the this object location
which has the compiled dll of the current UnitTest:
Clearly this is not where we should be looking at
So, I guess the next step is to download the ChromeDriver:
Which unziped looks like this:
Using the technique described in Using VisualStudio C# REPL to quickly find issue let’s see if we can set the Path Dynamically.
Here is the current path:
Trying to run the ChromeDriver.exe directly doesn’t work (because it is not being resolved in the current Path)
Here is a temp location for the ChromeDriver.exe:
Testing adding a new path:
Here is the code that updates the current (process) Environment Path and starts ChromeDriver.exe directly:
Next we add this code to the CreateDriver method:
and the unit test will execute :)
Add the option to detect when this is a chrome test:
which means that that code will not be executed when we are running the tests in Firefox:
Final step is to remove the hard dependency on the ChromeDriver.exe, and download it on first run into a temp folder.
Open the C# REPL again, and define a temp folder inside O2’s temp folder (daily based):
This is where we want the ChromeDriver.exe file to exist:
Here is the code that downloads the ChromeDriver.exe (if not there)
Add this code to the CreateDriver method (with a bit of refactoring using Lambda methods)
If the ChromeDriver.exe file doesn't exist (note the empty directory) it will be downloaded on first run:
After the run the ChromeDriver.exe will be in the right location:
It will need to authorized on first run (if you have a firewall enabled)
And all is working as it should (the UnitTest will successfully run on Chrome)
This code still needs quite a bit of refactoring but it already solves a really hard problem (which is to remove a hardcoded dependency on ChromeDriver.exe and prevent us from needing to add ChromeDriver.exe to GitHub)