首页 > 解决方案 > Selenium - 调用项目 DLL 来运行测试用例 c# 问题

问题描述

我试图通过从 cmd 调用调试 dll 来运行测试用例,但由于我在日志文件中发现的错误,所有测试都失败了:

测试方法 SeleniumUnitTest.SearchTests.SearchByProviderLocationTest 抛出异常:OpenQA.Selenium.DriverServiceNotFoundException:IEDriverServer.exe 文件在当前目录或 PATH 环境变量上的目录中不存在。驱动程序可以在 http://selenium-release.storage.googleapis.com/index.html下载。

IEDriverServer.exe不存在,但驱动程序已经在 DLL 目录中......当我从 Visual Studio 运行单元测试时我也没有问题。

我运行的命令是:

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\mstest.exe" /testcontainer:"C:\Users\John\Source\Repos\APP\Src\App.TestSelenium\bin\Debug\ App.TestSelenium.dll"

任何想法?

谢谢你。

标签: c#seleniuminternet-explorertesting

解决方案


有两种方法可以解决此问题

  1. 将 InternetExplorer.exe 存储在公共文件夹中并将其添加到环境 PATH 变量中。这是避免将驱动程序存储在解决方案文件夹中的麻烦的最佳方法
  2. 但是如果您想更好地控制驱动程序的版本,最好将所有驱动程序放在解决方案根文件夹中,然后在初始化驱动程序时指定路径

    var driver = new InternetExplorerDriver((Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
    

推荐阅读