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

4
我们正在使用capybara运行selenium-cucumber测试。这些测试在终端中每个都可以通过而没有问题。我知道这个错误涉及到一个端口无法使用,但是我不知道在哪里修复它以及如何修复。当我们尝试并行运行它们时,第一个测试通过,其余测试会失败并出现以下错误:
无法打开TCP连接到127.0.0.1:9516 (Connection refused - connect(2) for "127.0.0.1" port 9516) (Errno::ECONNREFUSED) features/welcome_login.feature:4:in `Given I navigate to "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个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接