无法打开到127.0.0.1:9516的TCP连接(连接被拒绝)

时间:2017-01-31 14:30:10

标签: ruby selenium cucumber automated-tests capybara

我们正在进行与水豚的硒黄瓜测试。这些测试中的每一个都将在终端内通过而没有问题。我知道这个错误涉及端口不可用但我无法弄清楚在哪里解决这个问题以及如何解决。当我们尝试并行运行它们时,第一次测试通过并且其余部分因此错误而失败:

无法打开到127.0.0.1:9516的TCP连接(连接被拒绝 - 连接(2)为“127.0.0.1”端口9516)(Errno :: ECONNREFUSED) features / welcome_login.feature:4:在'鉴于我导航到“http://www.example.com”'

这是我的env.rb代码:

require 'rubygems'
require 'selenium-cucumber'
require 'capybara'

# Store command line arguments
$browser_type = ENV['BROWSER'] || 'ff'
$platform = ENV['PLATFORM'] || 'desktop'
$os_version = ENV['OS_VERSION']
$device_name = ENV['DEVICE_NAME']
$udid = ENV['UDID']
$app_path = ENV['APP_PATH']

# check for valid parameters
validate_parameters $platform, $browser_type, $app_path

# If platform is android or ios create driver instance for mobile browser
if $platform == 'android' or $platform == 'iOS'

  if $browser_type == 'native'
    $browser_type = "Browser"
  end

  if $platform == 'android'
    $device_name, $os_version = get_device_info
  end

  desired_caps = {
    caps:       {
      platformName:  $platform,
      browserName: $browser_type,
      versionNumber: $os_version,
      deviceName: $device_name,
      udid: $udid,
      app: ".//#{$app_path}"
      },
    }

  begin
    $driver = Appium::Driver.new(desired_caps).start_driver
  rescue Exception => e
    puts e.message
    Process.exit(0)
  end
else # else create driver instance for desktop browser
  begin
    $driver = Selenium::WebDriver::for(:"#{$browser_type}")
    $driver.manage().window()
  rescue Exception => e
    puts e.message
    Process.exit(0)
  end

end

我可以做什么来让这些测试在并行运行时通过(因为它们在从终端单独运行时会通过?我会编写什么代码以及在哪里放置此代码以获得测试以查找开放端口?

非常感谢任何帮助。我是自动化测试的新手,这是一个非常大的挑战。

1 个答案:

答案 0 :(得分:1)

我在MacOs 10.11.6上遇到了同样的错误,以下问题解决了这个问题:

找到chromedriver

~/P/m/web-automation (master ⚡↩) which chromedriver
/Users/mesutgunes/.rbenv/shims/chromedriver

删除它

rm /Users/mesutgunes/.rbenv/shims/chromedriver

尝试重新链接它,按照说明操作:

~/P/m/web-automation (master ⚡↩) brew link chromedriver
Linking /usr/local/Cellar/chromedriver/2.30...
Error: Could not symlink bin/chromedriver
Target /usr/local/bin/chromedriver
already exists. You may want to remove it:
  rm '/usr/local/bin/chromedriver'

To force the link and overwrite all conflicting files:
  brew link --overwrite chromedriver

To list all files that would be deleted:
  brew link --overwrite --dry-run chromedriver