C#selenium max sessions

时间:2014-10-30 17:06:30

标签: c# selenium selenium-webdriver

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

我无法同时启动4/5以上的实例? 如何增加最大会话数?

    MyPool = CustomThreadPool.Instance;
    List<Task> tasks = new List<Task>();

    for (int ctr = 1; ctr <= 15; ctr++)
    {
        tasks.Add(Task.Factory.StartNew(() =>
        {
            IWebDriver _driver = new FirefoxDriver();
            _driver.Navigate().GoToUrl("http://www.msn.com");
            Thread.Sleep(5000);
            _driver.Close();
            _driver.Quit();
        }));
    }
    Task.WaitAll(tasks.ToArray());

1 个答案:

答案 0 :(得分:1)

我假设您正在使用网格。我已经回答了类似的问题here

基本上,您可以通过配置json文件控制节点及其大小。它看起来像这样:

{
  "capabilities":
      [
        {
          "browserName": "*chrome",
          "maxInstances": 2,
          "seleniumProtocol": "Selenium"
        }
        ... (any other browser capabilities here)
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 10,
    "port": 5555,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444
  }
}

关键是maxSessionmaxInstances