简体   繁体   English

C#中的硒网格

[英]Selenium Grid in C#

I'm trying to run my tests in another local machine, but i always end up failing! 我试图在另一台本地计算机上运行测试,但是我总是以失败告终! I've seen videos implementing successfully in JAVA, but I'm trying to do it through c#. 我看过视频在JAVA中成功实现,但是我正在尝试通过c#来实现。

Any Ideas are most appreciated! 任何想法都非常感谢!

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;
    }
  1. You should use remote uri of your grid instance instead of local and ensure that you have chrome installed at least on one of your nodes. 您应该使用网格实例的远程uri而不是本地的uri,并确保至少在一个节点上安装了chrome。 If you want to use selenium grid locally start local hub first using selenium-server-standalone.jar. 如果要在本地使用Selenium网格,请首先使用selenium-server-standalone.jar启动本地中心。 You should use info from here 您应该从这里使用信息

  2. Also you don't need this code: 您也不需要此代码:

     driver = new ChromeDriver();` - you need RemoteWebDriver directly 
  3. For me this code works perfectly: 对我来说,这段代码可以完美地工作:

     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) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM