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

Squish中无法加载/显示GUI窗口问题求助

Squish半自动测试脚本无GUI窗口、无输出且持续运行的排查与修复

核心问题排查方向及修复步骤

1. 补全缺失的模块导入

原脚本缺少必要的模块引用,导致执行时隐式报错卡住。在test.py开头补充导入:

import subprocess
import sys
import os
from squish import squishinfo, test

2. 修正choicebox.py路径引用

原相对路径写法易出错,改用Squish官方API获取测试套件根目录,确保能找到choicebox.py:

def choicebox(msg, title, choices_array):
    cmd = [sys.executable]  # 使用Squish当前绑定的Python解释器,避免环境不兼容
    suite_path = squishinfo.testSuite
    cmd.append(os.path.join(suite_path, "choicebox.py"))
    cmd.append(msg)
    cmd.append(title)
    for c in choices_array:
        cmd.append(c)
    
    # 添加日志调试路径是否正确
    test.log(f"执行命令:{' '.join(cmd)}")
    
    s = os_capture(cmd)
    # ... 后续代码不变

3. 给子进程添加超时与错误捕获

原os_capture函数无超时机制,若子进程因GUI无法显示卡住,主进程会无限等待。修改函数:

def os_capture(cmd):
    try:
        process = subprocess.Popen(
            args=cmd,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            text=True
        )
        stdout, _ = process.communicate(timeout=30)  # 设置30秒超时
        return stdout
    except subprocess.TimeoutExpired:
        process.kill()
        test.log("子进程超时:GUI窗口未正常启动,已终止进程")
        return ""
    except Exception as e:
        test.log(f"子进程执行失败:{str(e)}")
        return ""

4. 验证依赖文件完整性

  • 确认easygui.py和choicebox.py已放在测试套件根目录(而非测试用例子文件夹)
  • 检查choicebox.py开头是否正确导入easygui:import easygui

5. 排查GUI显示权限

  • 本地运行时,确保Squish进程有显示器访问权限(避免在无头终端、远程桌面无显示环境下运行)
  • 若在CI/CD环境,需配置虚拟显示器(如Xvfb)才能显示GUI窗口

内容的提问来源于stack exchange,提问作者Srinivas R

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 04:37:32