一、Windows
准备工作。配置PC的测试环境
- 开启Win10开发者模式
- 保持屏幕常亮,辅助工具 https://www.zhornsoftware.co.uk/caffeine/
- 默认英文输入法
1. Application
待测试的程序, Windows可执行程序(.exe)
2. Server
WinAppDriver, 运行启动服务
Driver,请仔细阅读关于此Driver的要求限制
3. Client
测试脚本语言 - Python
- Python环境搭建
- 依赖库
安装三方库 Appium-Python-Client
和selenium
pip install Appium-Python-Client
pip install selenium
4. 测试脚本示例
测试脚本包括三个阶段
- 测试前 - 连接至Server, 一些准备工作
- 测试中 - 寻找控件,执行操作, 验证对比
- 测试后 - 结束后操作
import time
import unittest
from appium import webdriver
from selenium.webdriver.common.keys import Keys
class AddLocalFileTests(unittest.TestCase):
@classmethod
def setUpClass(self):
# 连接到测试的App, 这里替换成你自己的App, 需要先启动App,然后再连接到它
desired_caps = {
}
desired_caps["app"] = "Root"
desired_caps["platformName"] = "Windows"
desired_caps["deviceName"] = "WindowsPC"
self._desktopDriver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities= desired_caps)
earthWindow = self._desktopDriver.find_element_by_name("ArcGIS Earth")
earthWindowhandle = earthWindow.get_attribute("NativeWindowHandle")
earthWindowhandle = hex(int(earthWindowhandle))
desired_caps_earth = {
}
desired_caps_earth["unicodeKeyboard"] = "true"
desired_caps_earth["appTopLevelWindow"] = earthWindowhandle
self._earthDriver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities= desired_caps_earth)
@classmethod
def tearDownClass(self):
# 断开连接
self._earthDriver.quit()
self._desktopDriver.quit()
def