【问题标题】:Failed to open TCP connection to 127.0.0.1:9516 (connection refused)无法打开到 127.0.0.1:9516 的 TCP 连接(连接被拒绝)
【发布时间】:2023-03-25 14:13:01
【问题描述】:

我们正在使用水豚进行硒黄瓜测试。这些测试中的每一个都将在终端内顺利通过。我知道这个错误涉及一个端口不可用,但我不知道在哪里解决这个问题以及如何解决。当我们尝试并行运行它们时,第一个测试通过,其余测试失败并出现以下错误:

未能打开到 127.0.0.1:9516 的 TCP 连接(连接被拒绝 - 连接(2)“127.0.0.1”端口 9516)(Errno::ECONNREFUSED) features/welcome_login.feature:4:in `鉴于我导航到“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

我可以做些什么来让这些测试在并行运行时通过(因为它们在从终端单独运行时通过?我会写什么代码以及我应该在哪里放置这些代码来让测试寻找一个开放的端口?

任何帮助将不胜感激。我是自动化测试的新手,这是一个相当大的挑战。

【问题讨论】:

    标签: ruby selenium cucumber automated-tests capybara


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-21
      • 2019-12-12
      • 2018-12-26
      • 2019-12-25
      • 1970-01-01
      • 2015-07-31
      • 2020-11-22
      • 1970-01-01
      相关资源
      最近更新 更多