Getting error - No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED)

2,274 views
Skip to first unread message

Sanjay Hiremath

unread,
Aug 21, 2013, 6:51:12 AM8/21/13
to watir-...@googlegroups.com
Hi Guys,

I have been getting this error recently. It was not the case earlier. I can't figure out what is going on. Can you please help me resolve the issue. I have copied the error message I am getting when I run my cucumber test on command prompt.

Please let me know if you need more info.

Many Thanks,
Sanjay

      No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED)
      C:/Ruby193/lib/ruby/1.9.1/net/http.rb:763:in `initialize'
      C:/Ruby193/lib/ruby/1.9.1/net/http.rb:763:in `open'
      C:/Ruby193/lib/ruby/1.9.1/net/http.rb:763:in `block in connect'
      C:/Ruby193/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
      C:/Ruby193/lib/ruby/1.9.1/timeout.rb:100:in `timeout'
      C:/Ruby193/lib/ruby/1.9.1/net/http.rb:763:in `connect'
      C:/Ruby193/lib/ruby/1.9.1/net/http.rb:756:in `do_start'
      C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in `start'
      C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1285:in `request'
      C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:83:in
 `response_for'
      C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:39:in
 `request'
      C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:40:in
`call'
      C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:629:in `raw
_execute'
      C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:607:in `exe
cute'
      C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:356:in `del
eteAllCookies'
      C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/options.rb:67:in `del
ete_all_cookies'
      C:/WorkingDirectory/AvivaHousehold/stories/features/support/env.rb:34:in `After'

Failing Scenarios:
cucumber features\payment_page.feature:68

Tadeu Panato

unread,
Aug 21, 2013, 6:02:05 PM8/21/13
to watir-...@googlegroups.com
more info

Sanjay Hiremath

unread,
Aug 30, 2013, 7:05:49 AM8/30/13
to watir-...@googlegroups.com
Hi guys,

I got this issue resolved.
The issue was I have hooks.rb which has
require 'watir-webdriver'
Before do
  @browser = Watir::Browser.new :firefox
end
After do
  @browser.close
end
I have the same lines of code in env.rb as well. For that reason 
The After block in hooks.rb is getting executed first which is closing the browser. When the After block in env.rb is executed the @browser instance variable is no longer to communicate with the browser.
Now I removed the code in hooks.rb and I am able to run all my scripts without any error.

Thanks for Cheezy for pointing me in right direction.

Cheers,
Sanjay

Bashir Osman

unread,
Sep 6, 2013, 11:26:12 AM9/6/13
to watir-...@googlegroups.com
Hi Sanjay, 

You can still use after, but make sure you use:

after(:all) do 
  @browser.close
end

Sanjay Hiremath

unread,
Sep 6, 2013, 11:57:06 AM9/6/13
to watir-...@googlegroups.com
Hi Bashir,
 
Do you mean I can still have after method as you mentioned in hooks.rb  ?
I did it, but it doesn't close the browser.
 
Thanks,
Sanjay


--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/Hfb43UiYxjA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Linkedin Profile: http://www.linkedin.com/in/sanjaykittali26

Bashir Osman

unread,
Sep 6, 2013, 12:20:37 PM9/6/13
to watir-...@googlegroups.com
Hi Sanjay, 

Here is a snippet of what I use. After all processes are complete it closes the browser

  before(:all) do
    @browser = Watir::Browser.new :phantomjs
    @browser.goto(Admin)
  end
  after(:all) do
    @browser.close
  end
  before(:each) do
   sleep 1
  end


On Wednesday, 21 August 2013 04:51:12 UTC-6, Sanjay Hiremath wrote:

esskay

unread,
Dec 31, 2013, 11:40:04 AM12/31/13
to watir-...@googlegroups.com
Hi Bashir - I get the same error like Sanjay - 
"No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED)
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:762:in `open'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:762:in `connect'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:744:in `start'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:1284:in `request'
"
but here we do not use Watir but use a custom framework we developed ourselves. In any case the env.rb contains the customized "After" hook as follows....

This After should trigger after scenario if it fails and not sure if that is causing this issue

We use ruby 1.9.3p125 (2012-02-16) [i386-mingw32] and the hooks.rb does not have @browser.close code in there like Sanjay pointed out. Can you please help? Can you suggest a better way to do this?

#post-scenario handler
After do |scenario|
	if (scenario.failed? && @test.verifyLogin())
		handleFailedStep(scenario)
		#Close and open browser to clean up
		if (ENV['NOKILL'].eql?('TRUE'))
			@test.logout()
			@test.clean()
		else
			@test.killBrowsers()
			@test.openBrowser()
		end
		@test.load()
		@test.login()
	end
end
Reply all
Reply to author
Forward
0 new messages