Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to localhost:21005 [localhost/127.0.1.1] failed: #1121

Closed
Inkimar opened this issue Jan 5, 2018 · 7 comments
Closed

Connect to localhost:21005 [localhost/127.0.1.1] failed: #1121

Inkimar opened this issue Jan 5, 2018 · 7 comments

Comments

@Inkimar
Copy link

Inkimar commented Jan 5, 2018

Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:21005 [localhost/127.0.1.1] failed:

System

  • Version: 0.19.1
  • Platform: Linux Mint 17.3 Rosa
  • Firefox: 57.0.1 (64-bit)
  • Selenium: 3.81

From the pom.xml

 <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.8.1</version>
        </dependency>

Testcase

public class Main {
public static void main(String[] args) throws InterruptedException {

    System.out.println("Hello world");
    System.setProperty("webdriver.gecko.driver", "/home/ingimar/Downloads/gecko/geckodriver-version-19/64bit/geckodriver")
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com");
}

}

Stacktrace

Hello world
1515145714065 geckodriver INFO geckodriver 0.19.1
1515145714070 geckodriver INFO Listening on 127.0.0.1:21005
Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:21005 [localhost/127.0.1.1] failed: Connection refused (Connection refused)
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'Ingimar-HP', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-32-generic', java.version: '1.8.0_141'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at Main.main(Main.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:21005 [localhost/127.0.1.1] failed: Connection refused (Connection refused)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:138)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:86)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
... 11 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 26 more

Process finished with exit code 1

newbie

I am running this as-is, my first selenium-project.
I am not starting 'geckodriver' from the terminal or anything - is that necessary ?
Do I have to install the geckodriver in a certain folder so that it can be located by firefox ?

best, Ingimar

@andreastt
Copy link
Contributor

Could you please attach a trace-level log from geckodriver? Read more about reporting actionable bugs in our contribution guidelines.

@Inkimar
Copy link
Author

Inkimar commented Jan 5, 2018

Hi @andreastt

I am New to Selenium.
I understand your feedback that I need to run the 'geckodriver' .

Somhow like this ?

geckodriver | tee >>geckodriver.log 2>>geckodriver.err.log
1515151344542 geckodriver INFO geckodriver 0.19.1
1515151344551 geckodriver INFO Listening on 127.0.0.1:4444

I understand the the default port is 4444.

When I run my java-program,java looks for the geckodriver on a random port like above (port 210005) next time I started it tried port 7328

1515145714070 geckodriver INFO Listening on 127.0.0.1:21005

Are there guidelines on how to pinpoint the port to i.e. 4444 in java ?

@andreastt
Copy link
Contributor

Presumably your Selenium client runs geckodriver for you. To enable trace logs to be emitted from geckodriver you need to pass a capability to it from your client. See the documentation in the contribution guidelines I linked to earlier as it should have examples for most major clients.

@Inkimar
Copy link
Author

Inkimar commented Jan 5, 2018

Hello,

I found these LogLevel-settings ( SeleniumHQ/selenium#3943 (comment) )

FirefoxOptions opts = new FirefoxOptions().setLogLevel(FirefoxDriverLogLevel.TRACE);
WebDriver firefoxDriver = new FirefoxDriver(opts);
 static void test2() throws InterruptedException {
        System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
        FirefoxOptions opts = new FirefoxOptions().setLogLevel(FirefoxDriverLogLevel.TRACE);
        WebDriver firefoxDriver = new FirefoxDriver(opts);
        firefoxDriver.get("http://www.google.com");
        Thread.sleep(5000);
        firefoxDriver.quit();
    }

Gives me the trace : which just seems to be on the client - I don't know how to reach the logs from the gecko-server

-- exec-maven-plugin:1.2.1:exec (default-cli) @ TestingSelenium ---
1515153459791	geckodriver	INFO	geckodriver 0.19.1
1515153459796	geckodriver	INFO	Listening on 127.0.0.1:11031
Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:11031 [localhost/127.0.1.1] failed: Connection refused (Connection refused)
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
System info: host: 'Ingimar-HP', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-32-generic', java.version: '1.8.0_141'
Driver info: driver.version: FirefoxDriver
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
	at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
	at is.ingimar.testingselenium.Main.test2(Main.java:45)
	at is.ingimar.testingselenium.Main.main(Main.java:26)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:11031 [localhost/127.0.1.1] failed: Connection refused (Connection refused)
	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
	at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:138)
	at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:86)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
	... 6 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
	... 21 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 22.096s
Finished at: Fri Jan 05 12:58:00 CET 2018
Final Memory: 7M/240M
------------------------------------------------------------------------

@Inkimar
Copy link
Author

Inkimar commented Jan 5, 2018

Hello.

My Mistake : I saw that my /etc/hosts-file was corrupted.
Now I have restored the file:

127.0.0.1 localhost

it is now working.

regards, i

@andreastt
Copy link
Contributor

Good you got it working!

@lock
Copy link

lock bot commented Aug 16, 2019

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.

@lock lock bot locked and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants