0
public static IWebDriver UserMultiUserSignIn (IWebDriver driver, string port, string hostName, string password, string Username)
{
    string name = Dns.GetHostName();
    ChromeOptions Options = new ChromeOptions();
    Options.AddAdditionalCapability(Username, "USERNAME");
    Options.AddAdditionalCapability(password, "ACCESS_KEY");
    driver = new RemoteWebDriver(new Uri("http://"+hostName+":"+port+ "/wd/hub"), Options.ToCapabilities());            

    return driver;
}


public static void RemoteServerLogin ()
{            
    string EMAUserName = System.Configuration.ConfigurationManager.AppSettings.Get("EMAUserName");
    string Password = System.Configuration.ConfigurationManager.AppSettings.Get("EMAPassword");
    string Port = System.Configuration.ConfigurationManager.AppSettings.Get("Port");
    string HostName = System.Configuration.ConfigurationManager.AppSettings.Get("Hostname");

    UserMultiUserSignIn(driver, Port, HostName, Password, EMAUserName);
}

Exception:

OpenQA.Selenium.WebDriverException: '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:9515 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.MakeHttpRequest(HttpRequestInfo requestInfo) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)'

1
  • How do you start your webdriver?
    – wec
    Oct 30, 2019 at 14:15

2 Answers 2

0

With chrome the setup is a little different. I'd need more info to help. Were you able to connect before and it recently stopped? If so I would say to make sure you have the most up to date driver. Is this the initial setup?

1
  • It'd be better to post this kind of answer as a comment rather than an answer, because you have more questions than actual answers.
    – pavelsaman
    Dec 8, 2019 at 15:20
0

The error message indicates that the client machine is unable to connect to the remote server. The error can be caused by several reasons such as wrong port number or hostname, network connectivity issues or the Selenium server is not running. In order to fix the issue, you can try the following steps:

1 Check the port and hostname: Verify that the port and hostname you are using are correct. You can do this by checking the configuration settings in your application or by contacting your system administrator.

2 Verify network connectivity: Ensure that there are no network connectivity issues between the client machine and the remote server. You can do this by pinging the remote server from the client machine or by contacting your network administrator.

3 Ensure that the Selenium server is running: Verify that the Selenium server is running on the remote machine. You can do this by checking the status of the server or by contacting your system administrator.

4 Try a different browser driver: If the above steps do not resolve the issue, you can try using a different browser driver such as Firefox or Internet Explorer.

Here is an updated code that includes some changes based on the above steps:

public static IWebDriver UserMultiUserSignIn (IWebDriver driver, string port, string hostName, string password, string Username)
{
string name = Dns.GetHostName();
ChromeOptions Options = new ChromeOptions();
Options.AddAdditionalCapability(Username, "USERNAME");
Options.AddAdditionalCapability(password, "ACCESS_KEY");

try
{
    driver = new RemoteWebDriver(new Uri("http://"+hostName+":"+port+ "/wd/hub"), Options.ToCapabilities());    
}
catch (WebDriverException e)
{
    Console.WriteLine("Failed to connect to remote server: " + e.Message);
    throw;
}        

return driver;
}

public static void RemoteServerLogin ()
{
string EMAUserName = System.Configuration.ConfigurationManager.AppSettings.Get("EMAUserName");
string Password = System.Configuration.ConfigurationManager.AppSettings.Get("EMAPassword");
string Port = System.Configuration.ConfigurationManager.AppSettings.Get("Port");
string HostName = System.Configuration.ConfigurationManager.AppSettings.Get("Hostname");

try
{
    UserMultiUserSignIn(driver, Port, HostName, Password, EMAUserName);
}
catch (WebDriverException e)
{
    Console.WriteLine("Failed to sign in to remote server: " + e.Message);
    throw;
}
}

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.