对两台测试设备进行测试,一台测试设备为 Android 设备,一台为 iOS 设备,类似用 iPhone 充当遥控器控制一台 Android 盒子。
因为手上暂时并没有 mac 环境,暂时用两台 Android 设备测试。
电脑开启两个 Appium 客户端,将其中一个客户端的端口改为:4725
运行后,验证了两个地址都正常返回: http://127.0.0.1:4723/ 与 http://127.0.0.1:4725/
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability("deviceName", "b1d12c6");
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.my.pkg");
capabilities.setCapability("appActivity", "com.my.pkg.LoadingActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
DesiredCapabilities capabilities2 = new DesiredCapabilities();
capabilities2.setCapability("device","Android");
capabilities2.setCapability("deviceName", "0123456789ABCDEF");
capabilities2.setCapability("platformVersion", "4.4.4");
capabilities2.setCapability("platformName", "Android");
capabilities2.setCapability("appPackage", "com.my.pkg");
capabilities2.setCapability("appActivity", "com.my.pkg.LoadingActivity");
driver2 = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities2);
client 端:
deviceName=b1d12c6 找不到 Session
org.openqa.selenium.remote.SessionNotFoundException:
Command duration or timeout: 5 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'RMTCNW20054', ip: '192.168.21.48', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: edc5d7c6-892f-401d-8f26-049d0ffab5eb
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{platform=LINUX, javascriptEnabled=true, appActivity=com.runmit.sweedee.LoadingActivity, browserName=Android, networkConnectionEnabled=true, desired={platformVersion=4.4.4, platformName=Android, deviceName=b1d12c6, appActivity=com.runmit.sweedee.LoadingActivity, device=Android, appPackage=com.runmit.sweedee}, locationContextEnabled=false, appPackage=com.runmit.sweedee, platformVersion=4.4.4, databaseEnabled=false, platformName=Android, deviceName=0123456789ABCDEF, webStorageEnabled=false, device=Android, warnings={}, takesScreenshot=true}]
......
测试设备:
被测程序在一台机器(deviceName=0123456789ABCDEF)启动了两次,而另外一台机器没有任何执行。
Appium 日志:
4723 端口的 Appium 服务端的日志中,deviceName 从 b1d12c6 变成了 0123456789ABCDEF
info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.4.4","deviceName":"b1d12c6","platformName":"Android","appActivity":"com.runmit.sweedee.LoadingActivity","device":"Android","appPackage":"com.runmit.sweedee"}}
info: Client User-Agent string: Apache-HttpClient/4.3.6 (java 1.5)
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : device
info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 05488004-2912-4243-ad70-690ebaf420e3
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.7.0_67
info: [debug] Checking whether adb is present
info: [debug] Using adb from D:\software\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe
warn: No app capability, can't parse package/activity
info: [debug] Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it's already on the device
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: D:\software\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe devices
info: [debug] 2 device(s) connected
info: Found device 0123456789ABCDEF
info: [debug] Setting device id to 0123456789ABCDEF
.......之后所有的日志中的 deviceName 全部为 0123456789ABCDEF
从现象上看,好像是 client 发送的 json 信息中 deviceName 确实是 b1d12c6,但是 Appium 在执行时,将 deviceid 设置成了另一台的测试设备的 deviceName 0123456789ABCDEF
导致设备 0123456789ABCDEF 上运行了两次脚本
是 Appium 本身不支持电脑运行多个服务端?还是我 client 的 bug?
两台电脑分别运行 Appium 服务端,端口的 ip 改为电脑真实的 ip,然后通过脚本操作两个 Appium 服务端分别控制两个测试设备,这样是 OK 的。但是平白多浪费一台电脑,感觉实在有点浪费。
设置 udid
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability("deviceName", "b1d12c6");
capabilities.setCapability("udid", "b1d12c6");
capabilities.setCapability("platformVersion", "4.4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.runmit.sweedee");
capabilities.setCapability("appActivity", "com.runmit.sweedee.LoadingActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
DesiredCapabilities capabilities2 = new DesiredCapabilities();
capabilities2.setCapability("device","Android");
capabilities2.setCapability("deviceName", "0123456789ABCDEF");
capabilities2.setCapability("udid", "0123456789ABCDEF");
capabilities2.setCapability("platformVersion", "4.4.4");
capabilities2.setCapability("platformName", "Android");
capabilities2.setCapability("appPackage", "com.runmit.sweedee");
capabilities2.setCapability("appActivity", "com.runmit.sweedee.LoadingActivity");
driver2 = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities2);
之后同时启动成功