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

如何使用QMetry自动化框架结合BDD步骤实现Windows应用自动化测试

QAF 结合BDD实现Windows桌面应用自动化方案

核心问题定位

你此前失败的核心原因是请求路径前缀不匹配:WinAppDriver默认不接受/wd/hub前缀,成功日志的请求路径为POST /session,而失败日志请求路径为POST /wd/hub/session,导致WinAppDriver无法识别请求。

环境准备

  • 已安装WinAppDriver并启动,监听端口为4723
  • 项目已引入QAF依赖、Appium Java Client依赖

项目配置

在QAF的application.properties配置文件中添加以下内容:

# 远程驱动地址,不带/wd/hub前缀
remote.server=http://127.0.0.1:4723/
# 驱动类型指定为appium远程驱动
driver.name=appiumRemoteDriver
# 移除默认的/wd/hub路径前缀
appium.additional.path=
# 桌面应用启动配置
appium.capabilities.platformName=Windows
appium.capabilities.app=C:\\Windows\\System32\\notepad.exe

BDD用例编写

新建notepad_test.feature文件,内容如下:

Feature: 记事本基础功能测试
  Scenario: 打开记事本并输入指定内容
    Given 启动记事本应用
    When 在编辑区域输入内容 "Some text"
    Then 记事本内容包含 "Some text"

步骤实现代码

新建步骤实现类,内容如下:

import com.qmetry.qaf.automation.step.QAFTestStep;
import com.qmetry.qaf.automation.ui.webdriver.QAFExtendedWebDriver;
import com.qmetry.qaf.automation.core.TestBaseProvider;
import org.openqa.selenium.By;

public class NotepadTestSteps {
    private final QAFExtendedWebDriver driver = TestBaseProvider.instance().get().getDriver();

    @QAFTestStep(description = "启动记事本应用")
    public void launchNotepad() {
        // 驱动会根据配置自动启动应用,此处直接切换到聚焦元素即可
        driver.switchTo().activeElement();
    }

    @QAFTestStep(description = "在编辑区域输入内容 {inputText}")
    public void inputContent(String inputText) {
        driver.findElement(By.className("Edit")).sendKeys(inputText);
    }

    @QAFTestStep(description = "记事本内容包含 {expectedText}")
    public void verifyContent(String expectedText) {
        String actualContent = driver.findElement(By.className("Edit")).getAttribute("Value");
        assert actualContent.contains(expectedText);
    }
}

注意事项

  • 配置文件中应用路径的反斜杠需要双写转义,避免JSON解析错误
  • WinAppDriver需要提前启动,且版本要和当前Windows系统版本匹配
  • Appium Java Client建议使用7.x版本,避免和QAF出现版本兼容问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 23:27:04