【问题标题】:Selenium Grid in C#C# 中的硒网格
【发布时间】:2016-07-07 00:04:14
【问题描述】:

我试图在另一台本地机器上运行我的测试,但我总是以失败告终!我已经看到视频在 JAVA 中成功实现,但我正在尝试通过 c# 来实现。

任何想法都非常感谢!

public class Driver
{ 
    public static IWebDriver Instance { get; set; }

    public static void Initialize()
    {
        IWebDriver driver;
        driver = new ChromeDriver();

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities = DesiredCapabilities.Chrome();
        capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
        capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));


        driver = new RemoteWebDriver(new Uri("http://localhost:4446/wd/hub"), capabilities);
    }
    public static void Close()
    {
        Instance.Dispose();
        Instance = null;
    }

【问题讨论】:

  • 您确定您的 Selenium 服务器在 http://localhost:4446/wd/hub 运行吗?我认为默认端口是 4444,而不是 4446。如果端口正常,则尝试将 localhost 更改为 http://127.0.0.1。启动 selenium 服务器时会打印有关地址的信息,例如:10:57:39.174 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub

标签: c# selenium-webdriver selenium-grid


【解决方案1】:
  1. 您应该使用网格实例的远程 uri 而不是本地,并确保您至少在其中一个节点上安装了 chrome。如果你想在本地使用 selenium 网格,首先使用 selenium-server-standalone.jar 启动本地集线器。你应该使用来自here的信息

  2. 你也不需要这个代码:

    driver = new ChromeDriver();` - you need RemoteWebDriver directly
    
  3. 对我来说,这段代码完美运行:

    var uri = 'uri_to_your_grid_hub';
    var capabilities =  new ChromeOptions().ToCapabilities();
    var commandTimeout = TimeSpan.FromMinutes(5);
    var driver = new RemoteWebDriver(new Uri(uri),capabilities,commandTimeout)
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    • 2018-06-15
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多