iOS 运行

WebDriverAgent 工程配置

image.png|500

需要提前准备一个开发者账号 $99

运行WebDriverAgent

工程运行

选择target
image.png|500
选择设备
image|500
运行
image.png|500

命令行运行

获取设备udid

1
idevice_id -l

cd WebDriverAgent工程目录下

1
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=设备的udid" USE_PORT=8100 test

命令行使用脚本执行

命令行的执行方式可以结合成sh脚本 ,这个步骤不是必须的

新建 sh 文件
cd WebDriverAgent工程目录下

1
vi start.sh

输入内容
1
2
3
4
5
6
7
8
9
10
# 解锁keychain,以便可以正常的签名应用,PASSWORD是你自己mac电脑的开机密码
# 这个步骤不是必须的
PASSWORD="xxxx"
security unlock-keychain -p $PASSWORD ~/Library/Keychains/login.keychain

# 获取设备的UDID
UDID=$(idevice_id -l | head -n1)

# 运行测试
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "id=$UDID" USE_PORT=8100 test

运行
1
sh start.sh

Appium server 运行

image.png|500
直接打开 Appium Server GUI - startServer

Appium inspector 运行

image.png|500

配置内容参考:

1
2
3
4
5
6
7
8
{
"platformName": "iOS",
"platformVersion": "15.3.1",
"deviceName": "iPhone8",
"automationName": "XCUITest",
"bundleId": "",
"udid": ""
}

Remote Path 要填 /wd/hub:

1
2
idevice_id -l // 获取 udid
ideviceinstaller -l // 获取bundleId

Android

配置内容参考

1
2
3
4
5
6
7
8
{
"platformName": "Android",
"platformVersion": "12",
"deviceName": "8BMY112RJ",
"appPackage": "",
"appActivity": "",
"automationName": "UiAutomator2"
}

获取 deviceName

1
adb devices

获取 platformVersion

1
adb shell getprop ro.build.version.release

获取 appActivity 和 appPackage

1
adb logcat|grep "START"

先执行上述指令,再冷启动APP
1
02-29 15:48:44.809  2215  3584 I ActivityTaskManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=包名在这/Activity在这 bnds=[585,1300][855,1694]} from uid 10153

遇到问题

Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported

1
2
Error
An unknown server-side error occurred while processing the command. Original error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. Read https://developer.android.com/studio/command-line/variables for more details

image.png|500
在 Appium gui - Edit Configurations 设置环境变量

Could not find a connected Android device

1
2
3
Error

Failed to create session. An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device in 20076ms.

查看手机有没有连接成功

Cannot start the ‘XXX’ application

1
Cannot start the 'XXX' application

确认 appActivity 是否正确,最好设置从启动页开始

Could not proxy command to the remote server

1
2
3
Error

Failed to create session. An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up

可能是执行appium 上个进程没有关闭导致的

  • 删除手机里的 Appium setting,给appium 换个服务端口
  • 重启大法 搞定