无法在 Teamcity 上启动 c#+SeleniumWebDriver+Specflow+Nunit 测试

Can't start c#+SeleniumWebDriver+Specflow+Nunit tests on Teamcity

现在尝试 运行 我的 Selenium 测试,使用 Teamcity 服务器。服务器安装在本地。 目前teamcity中的项目包含3个步骤:

  1. NuGet 安装程序。
  2. 步 Visual Studio 作为 运行ner。
  3. 使用 NUnit 作为 运行ner。

至此,第一步和第二步顺利完成。 第三步失败,日志中有下一条记录:

 [Step 3/3] Volvo.DigitalCommerce.AutomatedTests.dll (9m:11s)
[15:02:26][Volvo.DigitalCommerce.AutomatedTests.dll] Volvo.DigitalCommerce.AutomatedTests.Features.ChildSeat.CS_BaseFlowFeature.CS_GoingThroughFullFlow on Chrome (1m:01s)
[15:03:28][Step 3/3] Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 6915
[15:03:28][Step 3/3] Only local connections are allowed.
[15:03:28]
[Volvo.DigitalCommerce.AutomatedTests.Features.ChildSeat.CS_BaseFlowFeature.CS_GoingThroughFullFlow on Chrome] [Test Error Output]
-> warning: The previous ScenarioContext was already disposed.
[15:03:28]
[Volvo.DigitalCommerce.AutomatedTests.Features.ChildSeat.CS_BaseFlowFeature.CS_GoingThroughFullFlow on Chrome] TearDown method failed. Autofac.Core.DependencyResolutionException : An exception was thrown while invoking the constructor 'Void .ctor()' on type 'ChromeDriver'. ---> The HTTP request to the remote WebDriver server for URL http://localhost:6896/session timed out after 60 seconds. (See inner exception for details.)
  ----> OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:6896/session timed out after 60 seconds.
  ----> System.Net.WebException : The request was aborted: The operation has timed out.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
[15:03:28]
[Volvo.DigitalCommerce.AutomatedTests.Features.ChildSeat.CS_BaseFlowFeature.CS_GoingThroughFullFlow on Chrome] TearDown method failed. Autofac.Core.DependencyResolutionException : An exception was thrown while invoking the constructor 'Void .ctor()' on type 'ChromeDriver'. ---> The HTTP request to the remote WebDriver server for URL http://localhost:6896/session timed out after 60 seconds. (See inner exception for details.)
  ----> OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:6896/session timed out after 60 seconds.
  ----> System.Net.WebException : The request was aborted: The operation has timed out.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
   at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
   at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
   at Autofac.Core.Resolving.InstanceLookup.Execute()
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.Core.Container.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.ResolveNamed[TService](IComponentContext context, String serviceName, IEnumerable`1 parameters)
   at Volvo.DigitalCommerce.AutomatedTests.Features.ChildSeat.CS_BaseFlowFeature.CS_GoingThroughFullFlow(String browser) in C:\TeamCity\buildAgent\work\d7512e1031e4b296\Volvo.DigitalCommerce.AutomatedTests\Features\Child Seat\CS_BaseFlow.feature.cs:line 0
--WebDriverException
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
   at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   at lambda_method(Closure , Object[] )
   at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
--WebException
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
--TearDown
   at Volvo.DigitalCommerce.AutomatedTests.Features.ChildSeat.CS_BaseFlowFeature.ScenarioTearDown() in C:\TeamCity\buildAgent\work\d7512e1031e4b296\Volvo.DigitalCommerce.AutomatedTests\Features\Child Seat\CS_BaseFlow.feature.cs:line 0
[15:03:28][Volvo.DigitalCommerce.AutomatedTests.dll] Volvo.DigitalCommerce.AutomatedTests.Features.DigitalCommerce.FullFlowTestFeature.DC_FullFlow on Chrome (1m:01s)

任何人都可以帮助解决这个错误吗? 提前致谢, 瓦伦丁.

我们的自动化测试套件由于同样的原因而失败,在昨天尝试了几个小时的多种解决方案之后,我们的团队将此问题追溯到 Teamcity Build Agent Service: 运行ning系统帐户。这通常不应该是一个问题,但在我们的例子中,Chrome 在本地系统帐户下 运行 时无法 运行 / 打开。

当我们在我们的 CI 服务器上手动 运行 NUnit 并且没有遇到问题时,这被证明是问题。

更新服务后使用 new user account(密码永不过期,无法登录)

并在我们的构建引用的每个文件夹的安全设置下添加了新用户(除非您将其设置为管理员),Chrome驱动程序能够正确初始化并且套件 运行正常。

我们仍然不知道为什么 Chrome 在本地系统帐户下 运行 时无法初始化的根本问题,但我们猜测它与 Chrome 需要一些只有用户帐户才有的文件夹或文件(桌面,App_Data 等...)