You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Python脚本运行Squish Qt测试套件及解决连接错误

解决Squish测试套件运行时的连接拒绝问题

问题核心原因

报错RuntimeError: Could not connect to Squish server at host 127.0.0.1, port 4322: Connection refused的本质是:squishrunner默认会尝试连接本地4322端口的Squish服务,但该服务未启动、端口被占用,或调用参数未配置为本地运行模式。


解决步骤

1. 最简便方案:让squishrunner本地运行(无需单独启动服务)

修改Python脚本,给squishrunner添加--local参数,强制其在本地进程内运行测试,不再尝试连接外部Squish server。同时优化路径拼接逻辑避免跨平台错误:

import os
import subprocess

# 替换为你的实际路径和参数
current_working_directory = os.getcwd()
folder_path = os.path.join(current_working_directory, "test_suits")
squishrunner_path = "C:\\path\\to\\squish\\bin\\squishrunner.exe"  # Windows示例,Linux/macOS替换为对应路径
report_filename = os.path.join(current_working_directory, "test_report.html")

test_suite_names = []
if os.path.exists(folder_path):
    # 遍历并筛选出测试套件目录(排除非目录文件)
    test_suite_names = [
        os.path.join(folder_path, item) 
        for item in os.listdir(folder_path) 
        if os.path.isdir(os.path.join(folder_path, item))
    ]

# 构建测试命令,添加--local参数
commands = [
    [
        squishrunner_path,
        "--local",  # 关键参数:本地运行,无需连接外部server
        "--testsuite", test_suite_path,
        "--testcase", "tst_master",
        "--reportgen", f"html,{report_filename}"
    ]
    for test_suite_path in test_suite_names
]

# 逐个执行测试命令
for command in commands:
    try:
        print(f"执行测试:{' '.join(command)}")
        subprocess.check_call(command)
    except subprocess.CalledProcessError as e:
        print(f"测试失败:{e}")

2. 备选方案:手动启动Squish Server

如果必须使用外部server模式,先手动启动Squish服务:

  • Windows:找到Squish安装目录下的bin\squishserver.exe,双击运行或用命令行:
    "C:\Program Files\froglogic\Squish 7.2.0\bin\squishserver"
    
  • Linux/macOS:
    /opt/froglogic/squish/bin/squishserver
    
  • 验证端口监听:
    # Windows
    netstat -ano | findstr :4322
    # Linux/macOS
    lsof -i :4322
    
    确认输出中有squishserver进程监听4322端口后,再运行原Python脚本。

额外排查点

  • 确认squishrunner_path路径正确:必须指向Squish安装目录bin文件夹下的可执行文件,路径含空格时需用引号包裹。
  • 端口冲突处理:若4322被占用,可指定其他端口,启动server时加--port 4323,运行squishrunner时加--port 4323。
  • 权限问题:Windows下需以管理员身份运行脚本,避免端口绑定失败。
  • 许可证有效性:无效的Squish许可证会导致server无法启动,检查许可证状态。

内容的提问来源于stack exchange,提问作者P Sairam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 21:27:27