VS 2015 - Running Unit tests from cmd line, problems with initializing chromedriver

desmo

Member
Joined
Jan 3, 2018
Messages
14
Programming Experience
Beginner
First of all: The unit tests in this case are functional tests using Selenium Webdriver. The reason for this is that I like the VS unit test framework, and find it easy to organize the solution with separate projects for the actual automation and the tests.

This is a framework which is organized into different projects for web page automation, test data handling, helper functions, Selenium WebDriver implementation etc. It's organized like this:

Solution: Automation
Project: Common (class library) - includes classes for accessing page elements, site navigation and the Selenium ChromeDriver (singleton) object.
Project: Automation (class library) - contains classes for the site pages, menus and functionality.
Project: TestData (class library) - contains classes for reading and writing test data from configuration and data file
Project: Windows functionality (class library) - contain classes for handling site login when normal authentication doesn't work, file upload dialogs etc.
Project: Tests (unit test project) - contains the functional tests, as Unit Tests

I have (or am planning to have) two ways to run the tests: From the VS Test Explorer and from an Excel file using VBA-macros to run MSTest.exe from the command line.

From Test Explorer:
This works like a charm. All libraries installed with NuGet (Selenium WebDriver, Selenium ChromeDriver, AutoIt) are loaded and everything is just peachy.

From the command line with MSTest.exe:
The basic tests that doesn't use Selenium (I call them framework health tests - more standard unit tests) work fine.
But all tests that uses Selenium Webdriver (that is, everything from opening Chrome and forward) does not. These fail with the following error (from the test result .trx file):

C#:
Initialization method FlowTests.BasicTests.OpenTests.OpenMyLabDrop2.Init threw exception. OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: 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..
at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl)
at OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService()
at Common.Selenium.GCDriver.Initialize() in d:\Source\Workspaces\QA\FlowAutomation\Common\Selenium\GCDriver.cs:line 19
at FlowTests.Base.MyLabDrop2Test.Init() in d:\Source\Workspaces\QA\FlowAutomation\FlowTests\Base\MyLabDrop2Test.cs:line 16

This is the way I run the tests from the command line:

C#:
MSTest.exe /resultsfile:d:\QA\testresults\autotests\regressiontests\opensitetests\test.trx /testcontainer:d:\Source\Workspaces\QA\Automation\Tests\bin\Debug\Tests.dll /test:Tests.BasicTests.OpenTests.OpenMyLab.Open_MyLab_StartPage_as_Specific_User

Now, this is a fairly standard error which means that the ChromeDriver isn't loaded. And if I got this when running the project(s) in VS Test Explorer, I would have something to investigate and troubleshoot.

However, when this happens ONLY when running the tests from the command line, I have no idea how to proceed. This have worked before, in another similar project, but I haven't been able to find any differences between the two.

It doesn't seem to matter where I run the test command from. And I've copied chromedriver.exe around on the system - even added it manually to the user profile's environment path - to no avail.

No Selenium Experts seem to be able to help me with this, either because it's so VS-specific or because no one ever runs it like this.

All suggestions, help and advice is greatly appreciated.
 
Top Bottom