2013-03-04 3 views
1

Я пытаюсь выполнить тестирование автоматизации с помощью «Selenium Remote Webdriver», но получаю исключение, когда пытаюсь подключиться к удаленному серверу.Почему мой код не подключается к удаленному веб-серверу Selenium?

Исключение:

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 127.0.0.1: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) 
    --- End of inner exception stack trace --- 
    at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) 
    at System.Net.HttpWebRequest.GetRequestStream() 
    at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecutor.cs:line 109 
    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 836 

Код я написал:

  DesiredCapabilities capabilities = DesiredCapabilities.Firefox(); 
      capabilities.Platform = new Platform(PlatformType.Vista); 
      capabilities.SetCapability("api_key", "REPLACE_API_KEY"); 
      capabilities.SetCapability("api_secret", "REPLACE_API_SECRET"); 


      var remoteAddress = new Uri("http://122.176.112.91:4444/wd/hub"); 

      // ... but only if it supports javascript 
      capabilities.IsJavaScriptEnabled = true; 


      // Get a handle to the driver. This will throw an exception 
      // if a matching driver cannot be located 
      IWebDriver driver = new RemoteWebDriver(remoteAddress, capabilities); 
      driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30)); 


      // Query the driver to find out more information 
      ICapabilities actualCapabilities = ((RemoteWebDriver)driver).Capabilities; 

Пожалуйста, помогите мне разобраться в этом prolem.

Заранее спасибо.

+3

Ну есть экземпляр Селен прослушивания на 'Http: //122.176.112.91: 4444/Wd/hub'? – Arran

+0

брандмауэр вопрос возможно? –

+0

попытайтесь изменить номер порта. Надеюсь, поможет. – Hemanth

ответ

0

Трассировка стека указывает, что локальная машина активно отказывается от любых подключений. Дважды проверьте, что Firefox разрешен для всех портов брандмауэрами.

К сожалению, я столкнулся с этой проблемой, даже когда брандмауэр открыт: C# + VisualStudio + Multiple WebDriver instances = SocketExceptions

Смежные вопросы