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

如何在Ubuntu中运行Python脚本,借助QtWebDriver测试Qt应用?

用Selenium+QtWebDriver测试QtCalculator的实操过程

最近我折腾了用Selenium结合QtWebDriver来测试QtCalculator,全程是按照QtWebDriver官方方案里的「WebDriver创建应用」(选项2)来走的,具体步骤给大家捋一捋:

第一步:搞定示例项目与环境

首先我克隆了带有Qt计算器示例的QtWebDriver分支项目,执行的命令是:

git clone -b add_app_example https://github.com/cisco-open-source/qtwebdriver.git

克隆完成后,我重新构建了QtWebDriver,接着启动了WebDriver服务,确保测试环境准备妥当。

第二步:编写Python测试脚本

之后我写了一个简单的Python测试脚本,用来通过Selenium调用QtWebDriver来操作计算器,核心代码片段如下:

#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# 这里可以继续补充测试逻辑,比如连接WebDriver、定位计算器控件、模拟按键操作等
# 示例:
# driver = webdriver.Remote(command_executor='http://localhost:9515', desired_capabilities={'browserName': 'qt'})
# 定位计算器上的数字按钮和操作按钮,执行计算流程

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:37:43