Appium

Appium是一个开源的应用测试自动化框架,支iOS、Android和Windows平台上的应用,包括原生应用、移动Web应用和混合应用。

简介

时间轴

原理

drawio: Appium原理

了解更多 >> Appium 中文文档:Appium 介绍


安装

Appium可以通过npm安装或下载Appium Desktop安装桌面版。

Appium Desktop

了解更多 >> Appium 文档:Appium 介绍


使用npm安装

$ npm install -g appium
$ appium

了解更多 >> Appium 文档:Appium 介绍


不同语言客户端

根据使用的语言安装Appium客户端,用于连接操作Appium。

语言 / 框架 安装 Github 仓库
Python pip install Appium-Python-Client https://github.com/appium/python-client
Java https://github.com/appium/java-client
C# (.NET) https://github.com/appium/appium-dotnet-driver
Ruby https://github.com/appium/ruby_lib, https://github.com/appium/ruby_lib_core

了解更多 >> Appium 中文文档:支持 Appium 服务器的客户端程序库列表


驱动

名称 描述 网站
Uiautomator2
WinAppDriver

辅助工具

名称 描述 官网
Appium Inspector UI分析软件,查看和定位手机应用或windows软件的元素的信息。
安装:https://github.com/appium/appium-inspector/releases 页面下载最新版本安装
https://github.com/appium/appium-inspector
Inspect UI分析软件,查看windows软件的元素的信息。Inspect.exe包含在Windows SDK中。安装或在C:\Program Files (x86)\Windows Kits\10\bin目录中搜索inspect,选择对应平台的inspect.exe打开即可。 https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/ https://learn.microsoft.com/en-us/windows/win32/winauto/inspect-objects
Accessibility Insights

快速入门

测试Android应用

测试iOS应用

测试Windows应用

Python语言示例。安装好以下软件:

打开一个记事本,输入hello,world

  • 1.启动Appium服务器
  • 2.新建一个text.pyw文件,输入如下代码,并运行。
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

desired_caps = {}
desired_caps['app'] = r"C:\Windows\System32\notepad.exe"
desired_caps['platformName'] = "Windows"
driver = webdriver.Remote(
    command_executor='http://127.0.0.1:4723/wd/hub',
    desired_capabilities=desired_caps)
driver.find_element(By.NAME, '文本编辑器').send_keys("hello, world").send_keys(Keys.ENTER)

常见错误:

Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

Appium默认监听地址为http://127.0.0.1:4723/wd/hub,如果Python中输入的是http://127.0.0.1:4723http://127.0.0.1:4723/wd/hub/就会出现上面错误。

Message: Bad capabilities. Specify either app or appTopLevelWindow to create a session

如果直接使用微软的WinAppDriver监听,Appium-Python-Client 2 的生成capabilities增加了"appium:,与WinAppDriver的capabilities格式不一致,如:{"capabilities": {"firstMatch": [{}], "alwaysMatch": {"appium:app": .......。解决办法,直接使用appium服务器(自带WinAppDriver)或者安装Appium-Python-Client 1。

了解更多 >> Appium 文档:Windows Appium 中文文档:运行测试\使用 Appium 运行你的测试程序(Windows) WinAppDriver 文档:您可以单独使用WinAppDriver ,也可以与Appium一起使用 WinAppDriver 示例: Python/CalculatorTest


资源

官网

网站