該教程是windows UI入門級,可以讓一個初學者搭建起windows UI自動化測試平台的基本框架功能。所有資料都在百度鏈接

詳細步驟如下:
一、下載windwosUI測試驅動程序 WindowsApplicationDriver-1.2.99-win-x64 .exe和UISpy.exe windows UI元素獲取工具
github下載鏈接:https://github.com/Microsoft/WinAppDriver/releases
(如果不好訪問可以從百度雲盤下載:鏈接: https://pan.baidu.com/s/1HjpuHMabLOjKlOVyXgsgKQ 提取碼: yr9h 注意:百度網盤可能不最新版本)
windows UI元素獲取工具只能從百度網盤獲取(也可以自行去網上下載,這里不提供下載鏈接)
二、安裝驅動
雙擊安裝完成即可。安裝完路徑默認為C:\Program Files\Windows Application Driver\WinAppDriver.exe
二、設置開發者模式
這里以windows10 設置開發者為例
1、點擊設置選擇更新和安全

2、點擊開發者,打開開發者設置

三、啟動運行
如果是本機訪問雙擊運行WinAppDriver.exe即可。如果是遠程方式訪問需要在程序后面添加IP地址和端口參數方式啟動 例如:WinAppDriver.exe 主機ip地址 端口 (WinAppDriver.exe 192.168.1.88 4723 )

驅動安裝和運行到此結束。下面使用python為例子來遠程連接和測試。
四、連接測試
安裝第三方插件appium :pip install Appium-Python-Client==1.1.0(注意:高版本可能有不兼容問題)
1、啟動應用程序
from appium import webdriver
desired_caps = {}
desired_caps["app"] = r"E:\工具\wav生成工具\wav生成工具\語音自動生成器.exe"
server_url = "http://127.0.0.1:4723" #我這里是本地訪問
driver = webdriver.Remote(server_url, desired_caps)

2、測試輸入一段文字
先運行被測程序->再運行UISpy
在UISpy中找到對應的程序名字點擊如下圖:

找到輸入框->找到對應的id號

測試代碼如下:
from appium import webdriver
import time
if __name__ == "__main__":
desired_caps = {}
desired_caps["app"] = r"E:\工具\wav生成工具\wav生成工具\語音自動生成器.exe"
server_url = "http://127.0.0.1:4723"
driver = webdriver.Remote(server_url, desired_caps)
time.sleep(2)
text_input = driver.find_element_by_accessibility_id("110")
text_input.clear()
text_input.send_keys("UI 自動化測試")
time.sleep(1)
save = driver.find_element_by_accessibility_id("350")
save.click()
time.sleep(1)
start = driver.find_element_by_accessibility_id("100")
start.click()
到此一個windwos UI自動化測試的基本環境搭建好了。
