- 启动Appium-GUI 点击 启动服务器
![](https://img2024.cnblogs.com/blog/1041030/202406/1041030-20240629025920251-136650989.jpg)
- 启动模拟器Genymotion
![](https://img2024.cnblogs.com/blog/1041030/202406/1041030-20240629030108510-1309022936.jpg)
3. 在命令行窗口adb devices 查看模拟器IP
![](https://img2024.cnblogs.com/blog/1041030/202406/1041030-20240629030214959-1194742425.jpg)
- 打开pycharm编写简单脚本如下
点击查看代码
from appium import webdriver
#import unittest
desired_caps={}
desired_caps['platformName']='Android'
desired_caps['deviceName']='192.168.29.102:5555'
desired_caps['platforVersion']='5.1.1'
desired_caps['appPackage']='com.android.calculator2'
desired_caps['appActivity']='com.android.calculator2.Calculator'
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
#driver.find_element_by_id('com.android.calculator2:id/del').click()
driver.find_element_by_android_uiautomator('text("7")').click()
driver.find_element_by_android_uiautomator('text("+")').click()
driver.find_element_by_android_uiautomator('text("9")').click()
driver.find_element_by_android_uiautomator('text("=")').click()
s=driver.find_element_by_id('com.android.calculator2:id/result').text
assert s=='16'
if s=='16':
print("计算结果正确")
- 运行脚本观察模拟器变化
![](https://img2024.cnblogs.com/blog/1041030/202406/1041030-20240629030431082-892500044.jpg)
- 查看控制台运行情况
![](https://img2024.cnblogs.com/blog/1041030/202406/1041030-20240629030455613-699690466.png)