cvakiitho
cvakiitho

Reputation: 1393

Parallel-test Cucumber watir testing with phantomjs ECONREFUSED

I`m having issues with phantomjs with my parallel testing, firefox is running fine. I use parallel_tests, watir-webdriver, and Cucumber.

No connection could be made because the target machine actively refused it. - connect(2) for "127.0.0.1" port 8910 (Errno::ECONNREFUSED)

Tests are running via:

parallel_cucumber features/parallel_tests -n 3

After some debugging I figured the problem appears when first process is finished with testing, it somehow kills all phantomjs browser instances.

This is env.rb setup:

browser = Watir::Browser.new :phantomjs, args: %w(--ignore-ssl-errors=true)

Before do
  @browser = browser
  @browser.cookies.clear
end

at_exit do
  browser.close
end

I also tried not closing browser at all, but with no luck, it is somehow done automatically. I tried both Windows, and CentOS.

phantomjs -v 
2.0.0
Using cucumber 1.3.19
Using selenium-webdriver 2.45.0
Using watir-webdriver 0.6.11
Using parallel 1.4.1
Using parallel_tests 1.3.9

I have a feeling it is a phantomjs/webdriver bug...

Upvotes: 0

Views: 612

Answers (1)

Johnson
Johnson

Reputation: 1490

This is likely a race condition to port 8910 by your 3 phantom instances. Similar to this issue.

# env.rb
Before do
  sleep ENV['TEST_ENV_NUMBER'].to_i
  @browser = Watir::Browser.new :phantomjs, args: %w(--ignore-ssl-errors=true)
end

If I'm reading the ParallelTests source correctly, environment variable TEST_ENV_NUMBER is set to the process index for each process. So the first process has a TEST_ENV_NUMBER of 0. As long as that's the case, the Before hook above will sleep for that number of seconds before initializing Watir::Browser. That will stagger the the parallelization a bit, but it should remove the race condition.

Upvotes: 1

Related Questions