【问题标题】:Failed Parallel tests in C# with MbUnit framework and Selenium using Gallio and powershell with the Chrome Driver - all tests fail在 C# 中使用 MbUnit 框架和 Selenium 使用 Gallio 和带有 Chrome 驱动程序的 powershell 的并行测试失败 - 所有测试都失败
【发布时间】:2014-05-07 17:18:31
【问题描述】:

Test 解决方案有 2 个项目 - 一个带有测试方法的 Test 项目(它继承自具有详细编写的测试步骤的基类),另一个项目是包含常用方法的类库项目和测试的实际步骤。

使用此解决方案测试数据输入页面。

问题

当我使用 Selenium Grid 并行执行测试时,所有测试都失败了 - 它打开了 Chrome 浏览器,然后什么也没有。

测试报告说服务器超时了。

当我按顺序运行测试时,它们都通过了(没有 Selenium Grid)。

到目前为止我做了什么:

  1. 使用 Selenium Grid 2

1.1。启动集线器打开命令窗口(具有管理员访问权限)并在 selenium 目录中运行以下命令:

    java -jar selenium-server-standalone-2.5.0.jar -role hub

1.2。打开另一个命令窗口实例(具有管理员访问权限)并在 selenium 目录中运行以下命令:

    java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.chrome.driver=\chromedriver.exe -role wd -hub http://4444/grid/register> 

2.在powershell中运行以下测试:

    PS>run-gallio test.dll

3.使用chrome驱动

    DesiredCapabilities capability = DesiredCapabilities.Chrome();
    capability.SetCapability(CapabilityType.BrowserName, "chrome");
    driver = new RemoteWebDriver(capability);

4.在assemblyinfo.cs的主测试项目中-添加了以下属性:

    [assembly: DegreeOfParallelism(4)]
    [assembly: Parallelizable(TestScope.All)]

5.每个类都有Parallelizable属性,每个测试方法也有Parallelizable属性。

我尝试过的一些方法

  1. 使用 DesiredCapabilities 设置浏览器二进制位置

    DesiredCapabilities - capabilities.SetCapability("chrome.binary",this.binaryLocation); 
    

(Remote Webdriver Chrome throws a "path to the driver executable" error) 这对我不起作用。

  1. 在调用 hub 命令时设置 chrome 驱动 How to build remote Webdriver for Chrome (这会打开 chrome 浏览器,但之后什么都没有)

  2. 还看了这个:How to run multiple browsers on one hub using Selenium Grid2

  3. 也尝试了多线程,但没有成功(使用 ChromeDriver 而不是 RemoteWebDriver)。

我现在遇到的错误

Run-Gallio : [failed] Test/AddValue  Set Up
OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server -
--> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 4444
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6,Socket& socket, IPAddress address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)    

问题可能是什么?

我可以在 Selenium Grid 中尝试什么?所有指导将不胜感激。

不能从 selenium 或 C# 切换到其他任何东西。谢谢你。

编辑: 几天后,使用 Selenium-server-2.41.0 现在收到以下超时错误消息。

    OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://127.0.0.1:4444/wd/hub/session/fdb51889-b9b7-4e97-beea-44dcf9637b0c/element/0/value timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out  

在调用 chrome 的 remotedriver 时添加了超时跨度 DesiredCapabilities 能力 = DesiredCapabilities.Chrome(); driver = new RemoteWebDriver(capability); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(120));

这不起作用。有什么建议吗?

编辑 回答:设法解决了这个问题 - 页面上有错误,由于我这边的网络问题 - 页面没有完全加载,脚本会搜索元素。解决了这个问题 - 谢谢 Daniel 和 Faiz。

【问题讨论】:

  • 检查您的防火墙。这一行告诉你问题:System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 4444
  • 1.2 的命令中,您使用的是http://4444....错字?
  • 肯定需要先解决之前cmet中的问题。也用最新的selenium-server-standalone-2.41.0.jar,2.5.0版本老了。
  • 谢谢 Daniel Mann,会看看 And Arran - 在 1.2 命令中,它应该是本地主机,但无法在这篇文章中写出来,Faiz - 谢谢你 - 将使用 selenium服务器 2.41.0。再次感谢。
  • Faiz - 下载了您列出的 selenium 服务器版本,它似乎可以工作。不过仍在检查。谢谢。

标签: c# powershell selenium parallel-processing automated-tests


【解决方案1】:

应该是:

[assembly: DegreeOfParallelism(2)]
[assembly:Parallelizable(TestScope.All)]

我在管理最大会话数和最大实例数时遇到了一些问题。所以在运行节点时请按如下标记。

java -Dwebdriver.chrome.driver="C:\ChromeDriver\chromedriver.exe" -jar selenium-server-standalone-2.42.2.jar -role node -hub http://localhost:4444/grid/register -port 5555 -browser "browserName=chrome,maxSession=1,maxInstances=1,platform=WINDOWS,ensureCleanSession=true"

【讨论】:

  • 谢谢你,Krishna 和 Serpiton。
  • 这就是我在 assemblyInfo.cs 中的内容,但它仍然一次运行一个。我也有 [TestClass] [Parallelizable]
猜你喜欢
  • 1970-01-01
  • 2011-05-01
  • 2011-02-16
  • 1970-01-01
  • 2020-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多