# Appium **Repository Path**: ForTheDream/appium ## Basic Information - **Project Name**: Appium - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-08-11 - **Last Updated**: 2021-08-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Appium 环境搭建手册 [appium](https://appium.io)是一套开源的自动化测试框架,可以很方便的进行iOS App的自动化测试。接下来我们简述一下Appium的环境搭建。 ## 配置 - 由于我们本次着眼于iOS App的自动化测试,因此**必须在MacOS中**完成。 操作系统版本需要为MacOS 11.0及以上。 - 安装Xcode,在AppStore中搜索`Xcode`点击下载安装即可 - 安装`Command Line Tools`,打开`Terminal` 执行以下命令 ```shell xcode-select --install ``` - 安装`Node`,打开`Terminal` 执行以下命令 ``` shell brew install node ``` > 如果提示找不到命令 `command not found: brew`, [点击这里安装](https://brew.sh) berw是MacOS中一个流行的包管理器 - 安装`Appium`,打开`Terminal` 执行以下命令 ```shell npm install -g appium ``` 至此`Appium`已经安装成功, 接下来我们来配置用于iOS自动化测试的`Driver`(不了解driver?[点击这里了解](http://appium.io/docs/en/drivers/ios-xcuitest/index.html)) ## Driver 在iOS模拟器进行自动化测试,只需要系统版本高于9.3即可,不需要进行额外的配置。如果需要在iOS真机进行测试则需要以下配置流程 - **必须**拥有一个加入苹果开发者计划的AppleID (即iOS开发者账号) - 打开Xcode, 按快捷键`Command + ,`然后选择`Accounts`点击左下角的`+`然后选择Apple ID登录开通苹果开发者计划的AppleID - 登录[developer.apple.com/account](https://developer.apple.com/account)然后点击侧边栏的`Membership`找到你开发者账号对应的TeamID (如果不是很清楚可以找iOS开发帮忙,找到以后记录下来) 好的,到这一步我们基础环境需要的所有资料都已经准备妥当,下面我们来写一个简单的用例跑一下。 ## 第一个自动化测试用例 - 找iOS开发拿到待测试的真机安装包(例如`demo.ipa`)和对应的`AppID`(例如 `icu.faraday.demo`) - 将真机链接到电脑,并信任电脑 - 执行以下命令并将测试机的相关信息保存起来 ``` shell # 保存udid xcrun xctrace list devices ``` 接下来的操作都需要系统已经安装`python3`如果还未安转可使用`brew install python3`来安装 - 安装appium的python客户端 ``` shell pip3 install Appium-Python-Client ``` - 建立一个文件 `main.py` 并`copy`以下代码 ``` python # iOS environment from appium import webdriver desired_caps = dict( platformName='iOS', platformVersion='14.4', # 你手机对应的系统版本号 automationName='XCUITest', deviceName='拖拉机🚜', # 手机对应的名字 app="xxx/xxx.ipa" # 你将要测试的ipa包 ) driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) el = driver.find_element_by_accessibility_id('item') el.click() ``` - 启动`Appium`服务, 打开`Terminal`执行 ``` shell appium ``` - 打开一个新的`Terminal`窗口,用于执行我们的测试用例 ``` shell python3 main.py ``` 好的你的第一个用例跑起来啦