cashanzlo
cashanzlo

Reputation: 121

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#.

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;
    }

Upvotes: 0

Views: 6040

Answers (1)

Dima Dubyk
Dima Dubyk

Reputation: 152

  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. If you want to use selenium grid locally start local hub first using 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)
    

Upvotes: 1

Related Questions