在c#中使用MbUnit框架进行并行测试失败,在Selenium中使用Gallio和powershell与Chrome

本文关键字:Gallio Selenium Chrome powershell 并行 MbUnit 框架 测试 失败 | 更新日期: 2023-09-27 18:02:08

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

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

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

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

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

我做了什么:

  1. 使用Selenium Grid 2

1.1。要启动hub,请打开命令窗口(具有管理员权限),并在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); 
    

(远程Webdriver Chrome抛出一个"路径到驱动程序的可执行"错误)这对我不起作用

  • 在调用hub命令时设置chrome驱动程序如何为Chrome构建远程Webdriver(这打开了chrome浏览器,但之后什么也没有)

  • 也看了这个:如何使用Selenium Grid2在一个集线器上运行多个浏览器

  • 也尝试多线程,但没有工作(使用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或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中调用远程驱动程序时增加了超时时间DesiredCapabilities能力= DesiredCapabilities. chrome ();driver = new RemoteWebDriver(capability);.Timeouts driver.Manage () () .ImplicitlyWait (TimeSpan.FromSeconds (120),

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

    编辑答案:设法解决了这个问题-页面上有错误,由于我这边的网络问题-页面没有完全加载,脚本会搜索元素。修好了-谢谢丹尼尔和法伊兹。

    在c#中使用MbUnit框架进行并行测试失败,在Selenium中使用Gallio和powershell与Chrome

    应该是:

    [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"