Appium selendroid 测试 android 不正确...

Rock · 2013年12月22日 · 最后由 Rock 回复于 2013年12月22日 · 2310 次阅读

hi。又有问题困扰我了。。

公司有个被测 app 是 android.webkit.WebView 类型的,我查了下,貌似 cap.setCapability("device", "android");不支持把?
我尝试改成了 cap.setCapability("device", "selendroid");但是跑了就出错

error:

info: Welcome to Appium v0.12.3

info: Appium REST http interface listener started on 0.0.0.0:4723
   info  - socket.io started

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}}}

debug: Appium request initiated at /wd/hub/status

GET /wd/hub/status 200 9ms - 144b

debug: Request received with params: {}

info: Not spawning instruments force-quit watcher since it only works on 10.9 and you have 10.8.5

debug: Appium request initiated at /wd/hub/session

debug: Request received with params: {"desiredCapabilities":{"platform":"MAC","app":"/Users/administrator/Documents/sf.apk","browserName":"","app-package":"com.sharefile.mobile.tablet","device":"selendroid","app-activity":".activities.SFAccountSelectActivity","version":"4.4.2"}}

info: Using local app from desiredCaps: /Users/administrator/Documents/sf.apk

info: Creating new appium session 0c281080-cb86-431f-970c-0ac0e6a0f6b6

info: Starting selendroid server

info: Checking whether selendroid is built yet

info: Selendroid server exists!
info: Preparing device for session

info: Checking whether app is actually present
info: Checking whether adb is present

info: [ADB] Using adb from /Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" devices

info: Trying to find a connected android device
info: [ADB] Getting connected devices...

info: [ADB] 1 device(s) connected

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" -s 072008a5 wait-for-device

info: Setting device id to 072008a5
info: [ADB] Waiting for device to be ready and to respond to shell commands (timeout = 5)

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" -s 072008a5 shell "echo 'ready'"

info: Starting logcat capture

info: Rebuilt selendroid apk does not exist, uninstalling any instances of it on device to make way for new one

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" -s 072008a5 uninstall com.sharefile.mobile.tablet.selendroid

info: Uninstalling com.sharefile.mobile.tablet.selendroid

debug: App was not uninstalled, maybe it wasn't on device?

info: Rebuilt selendroid server does not exist, inserting modified manifest

info: Inserting selendroid manifest

info: Checking whether aapt is present

error: Failed to start an Appium session, err was: Error: Could not find aapt in tools, platform-tools, or build-tools under "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk"; do you have android SDK installed into this location?

info: Cleaning up appium session
info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find aapt in tools, platform-tools, or build-tools under \"/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk\"; do you have android SDK installed into this location?)","origValue":"Could not find aapt in tools, platform-tools, or build-tools under \"/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk\"; do you have android SDK installed into this location?"},"sessionId":null}
POST /wd/hub/session 500 1882ms - 532b

debug: Appium request initiated at /wd/hub/status

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}}}

debug: Request received with params: {}

GET /wd/hub/status 200 1ms - 144b


看提示貌似是没有 aapt,但是我确认了下,路径下是有这个文件的,,,,

code:

DesiredCapabilities cap = new DesiredCapabilities();
        WebDriver wd = null;
        cap.setCapability(CapabilityType.BROWSER_NAME, "");
        cap.setCapability(CapabilityType.VERSION, "4.4.2");
        cap.setCapability(CapabilityType.PLATFORM, "MAC");//iPhone Simulator  iPad Device  Selendroid
        cap.setCapability("device", "selendroid");
        cap.setCapability("app", "/Users/administrator/Documents/sf.apk");//app.getAbsolutePath()    chromium ContactManager /Users/administrator/Documents/ContactManager.apk
        //cap.setCapability("launch", "true");
        cap.setCapability("app-activity", ".activities.SFAccountSelectActivity");//MainActivity   .ContactManager .activities.SFAccountSelectActivity
        cap.setCapability("app-package", "com.sharefile.mobile.tablet");//com.example.android.contactmanager

        wd = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);

        wd = new Augmenter().augment(wd);
        wd.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
共收到 20 条回复 时间 点赞
Rock #1 · 2013年12月22日 Author

这个问题 我根据 http://stackoverflow.com/questions/16619143/android-maven-could-not-find-tool-aapt 这个帖子 可以解决 但是又出了新的 error

error:

nfo: Using local app from desiredCaps: /Users/administrator/Documents/sf.apk

info: Creating new appium session 962652b6-1b4b-406f-a5c1-ee75ef25e39a

info: Starting selendroid server

info: Checking whether selendroid is built yet

info: Selendroid server exists!
info: Preparing device for session

info: Checking whether app is actually present
info: Checking whether adb is present

info: [ADB] Using adb from /Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb

info: Trying to find a connected android device

info: [ADB] Getting connected devices...

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" devices

info: [ADB] 1 device(s) connected

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" -s 072008a5 wait-for-device

info: Setting device id to 072008a5
info: [ADB] Waiting for device to be ready and to respond to shell commands (timeout = 5)

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" -s 072008a5 shell "echo 'ready'"

info: Starting logcat capture

debug: executing: "/Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb" -s 072008a5 uninstall com.sharefile.mobile.tablet.selendroid

info: Rebuilt selendroid apk does not exist, uninstalling any instances of it on device to make way for new one
info: Uninstalling com.sharefile.mobile.tablet.selendroid

debug: App was not uninstalled, maybe it wasn't on device?

info: Rebuilt selendroid server does not exist, inserting modified manifest

info: Inserting selendroid manifest

info: Checking whether aapt is present

error: Failed to start an Appium session, err was: Error: Required platform doesn't exist (API level >= 17)

info: [ADB] Using aapt from /Users/administrator/Downloads/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/aapt
info: Compiling manifest /tmp/com.sharefile.mobile.tablet/AndroidManifest.xml
info: Cleaning up appium session
info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Required platform doesn't exist (API level >= 17))","origValue":"Required platform doesn't exist (API level >= 17)"},"sessionId":null}
POST /wd/hub/session 500 1277ms - 248b

debug: Appium request initiated at /wd/hub/status

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}}}

debug: Request received with params: {}

GET /wd/hub/status 200 1ms - 144b

debug: Appium request initiated at /wd/hub/status

info: Responding to client with success: {"status":0,"value":{"build":{"version":"0.12.3","revision":"c8abd030c0cedcc387532f2aa986fd956e46eb4f"}}}

debug: Request received with params: {}

GET /wd/hub/status 200 1ms - 144b


Rock #2 · 2013年12月22日 Author

我的设备是 nexus7 4.4.2 版本的 难不成 shi 因为这个版本没法使用 selendroid?
要是这样的话 那我怎么测试 werbview 类型的呀?

Rock #3 · 2013年12月22日 Author

wo 换了低版本 de 也是这个错误

貌似官方代码的 bug, 他们会判断 android 的 sdk 目录, 找到一个跟你的手机 sdk 一致的目录.
但是里面只保存了最高到 4.3 的版本号, 你的 4.4 会出问题.
你把这段代码修改下, 加入 4.4 估计就可以了.

exports.getAndroidPlatform = function() {
  var androidHome = process.env.ANDROID_HOME;
  if (typeof androidHome !== "string") {
    logger.error("ANDROID_HOME was not exported!");
    return null;
  }

  var locs = ['android-4.2', 'android-17', 'android-4.3', 'android-18'];
  var res = null;
  _.each(locs, function(loc) {
    var platforms = path.resolve(androidHome , 'platforms')
    , platform = loc;
    if (fs.existsSync(path.resolve(platforms, platform))) {
      res = [platform, path.resolve(platforms, platform)];
    }
  });
  return res;
};

你测试下, 如果通过我就提个补丁给官方. 我这边没 4.4 的测试环境

Rock #6 · 2013年12月22日 Author

#4 楼 @seveniruby 大神呀 这段代码是在 appium 哪个文件夹/文件下呀?

#6 楼 @rockchensir 修改这个文件, lib/helpers.js, 尝试修改为

var locs = ['android-4.2', 'android-17', 'android-4.3', 'android-18', 'android-4.4', 'android-19', ];
Rock #8 · 2013年12月22日 Author

#7 楼 @seveniruby You are right! 改了后就解决了~可以顺利起来,然后我去尝试操作 WEBVIEW 里的内容又是一堆报错 我先研究下吧,不懂在上来问,THANKS!

Rock #11 · 2013年12月22日 Author

#9 楼 @lihuazhang
#10 楼 @seveniruby
尝试了好多次 ,还是又错误,不过这次不是在 appium,而是在我 app 的 webview 里出现了一个很长很长的错误,我觉得又点意义的就那个错误说明:illegal character in fragment at index 7903:....
下面就全部都是代码了。。很长很长

code:

    DesiredCapabilities cap = new DesiredCapabilities();
        WebDriver wd = null;
       // cap.setCapability(CapabilityType.BROWSER_NAME, "");
        cap.setCapability(CapabilityType.VERSION, "4.4.2");
        cap.setCapability(CapabilityType.PLATFORM, "MAC");//iPhone Simulator  iPad Device  Selendroid
        cap.setCapability("device", "selendroid");//
        cap.setCapability("app", "/Users/administrator/Documents/sf.apk");//app.getAbsolutePath()    chromium ContactManager /Users/administrator/Documents/ContactManager.apk Users/administrator/Documents/sf.apk
        //cap.setCapability("launch", "true");
        cap.setCapability("app-activity", ".activities.SFLoginActivity");//MainActivity   .ContactManager .activities.SFAccountSelectActivity
        cap.setCapability("app-package", "com.sharefile.mobile.tablet");//com.example.android.contactmanager

        wd = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);

        wd = new Augmenter().augment(wd);
        wd.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//        System.out.println(wd.getWindowHandles().size());
//        for (String s : wd.getWindowHandles()) {
//            System.out.println(s);
//            wd = wd.switchTo().window(s);
//        }

        Thread.sleep(5000);
       wd.switchTo().window("WEBVIEW");
        //CScreenShot.takeScreenShot(wd, "/Users/administrator/Documents/AND/1-screenshot", "0");
       // wd.findElement(By.xpath("//input[@type='text']")).click();
        wd.findElement(By.xpath("//input[@type='text']")).sendKeys("123");

在 wd.findElement(By.xpath("//input[@type='text']")).sendKeys("123"); 这句的时候出错的

screenshot:

#11 楼 @rockchensir 贴出来出错的 log 吧, 别截图了.

Rock #13 · 2013年12月23日 Author

#12 楼 @seveniruby 表示大脑有点捉急了。。。。这个错误是在 PAD 上出来的,我怎么把这些文字当到我的 MAC 上呀?

@seveniruby 请教一个问题,在使用 Selendroid 模式时,启动出错,内容如下 error: android.util.AndroidException: INSTRUMENTATION_FAILED: com.baidu.news.sel
endroid/io.selendroid.ServerInstrumentation

at com.android.commands.am.Am.runInstrument(Am.java:616)

at com.android.commands.am.Am.run(Am.java:118)

at com.android.commands.am.Am.main(Am.java:81)

at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)

at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:237)

at dalvik.system.NativeStart.main(Native Method)

info: Cleaning up appium session
error: Failed to start an Appium session, err was: Error: android.util.AndroidEx
ception: INSTRUMENTATION_FAILED: com.baidu.news.selendroid/io.selendroid.ServerI
nstrumentation

#14 楼 @chuyaoyao 插桩依赖重打包和签名, 你得先确保下百度新闻是可以重新编译的. 另外你可以单独跑下插桩的那个命令, 看看系统的错误信息..

@seveniruby 对 Selendroid 不太熟悉,求插桩的那个命令,apk 是可以编译的,我用了 Selendroid 的测试 apk,问题任然存在,我发现这里有个包 C:\Windows\Temp\selendroid.io.selendroid.testapp.apk
第一次运行产生这个包 但是报错 error: uncaughtException: Arguments to path.resolve must be strings date=Tue Jan
14 2014 19:30:43 GMT+0800 (中国标准时间), pid=9172, uid=null, gid=null, cwd=C:\
Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\appium, execPath=
C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node.exe, version=v0.10.17,
argv=[C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node.exe, C:\Users\c
huyaoyao\Downloads\AppiumForWindows\Appium\node_modules\appium\lib\server\main.j
s, --address, 127.0.0.1, --port, 4723, --app, C:\Users\chuyaoyao\Downloads\Appiu
mForWindows\Appium\apk\selendroid-test-app-0.7.0.apk, --app-activity, .HomeScree
nActivity, --app-pkg, io.selendroid.testapp, --no-reset], rss=42115072, heapTota
l=31562572, heapUsed=17334036, loadavg=[0, 0, 0], uptime=6235.2632985, trace=[co
lumn=15, file=path.js, function=Object.exports.resolve, line=116, method=exports
.resolve, native=false, column=23, file=C:\Users\chuyaoyao\Downloads\AppiumForWi
ndows\Appium\node_modules\appium\lib\devices\android\adb.js, function=moveManife
st, line=197, method=null, native=false, column=20, file=C:\Users\chuyaoyao\Down
loads\AppiumForWindows\Appium\node_modules\appium\lib\devices\android\adb.js, fu
nction=null, line=235, method=null, native=false, column=21, file=C:\Users\chuya
oyao\Downloads\AppiumForWindows\Appium\node_modules\appium\node_modules\async\li
b\async.js, function=null, line=548, method=null, native=false, column=13, file=
C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\appium\node_mo
dules\async\lib\async.js, function=null, line=224, method=null, native=false, co
lumn=13, file=C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\
appium\node_modules\async\lib\async.js, function=iterate, line=131, method=null,
native=false, column=25, file=C:\Users\chuyaoyao\Downloads\AppiumForWindows\App
ium\node_modules\appium\node_modules\async\lib\async.js, function=null, line=142
, method=null, native=false, column=17, file=C:\Users\chuyaoyao\Downloads\Appium
ForWindows\Appium\node_modules\appium\node_modules\async\lib\async.js, function=
null, line=226, method=null, native=false, column=34, file=C:\Users\chuyaoyao\Do
wnloads\AppiumForWindows\Appium\node_modules\appium\node_modules\async\lib\async
.js, function=null, line=553, method=null, native=false, column=7, file=C:\Users
\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\appium\lib\helpers.js,
function=exports.testZipArchive, line=79, method=testZipArchive, native=false],
stack=[TypeError: Arguments to path.resolve must be strings, at Object.expo
rts.resolve (path.js:116:15), at moveManifest (C:\Users\chuyaoyao\Downloads\
AppiumForWindows\Appium\node_modules\appium\lib\devices\android\adb.js:197:23),
at C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\appium\
lib\devices\android\adb.js:235:20, at C:\Users\chuyaoyao\Downloads\AppiumFor
Windows\Appium\node_modules\appium\node_modules\async\lib\async.js:548:21, a
t C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\appium\node_
modules\async\lib\async.js:224:13, at iterate (C:\Users\chuyaoyao\Downloads\
AppiumForWindows\Appium\node_modules\appium\node_modules\async\lib\async.js:131:
13), at C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\ap
pium\node_modules\async\lib\async.js:142:25, at C:\Users\chuyaoyao\Downloads
\AppiumForWindows\Appium\node_modules\appium\node_modules\async\lib\async.js:226
:17, at C:\Users\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\ap
pium\node_modules\async\lib\async.js:553:34, at exports.testZipArchive (C:\U
sers\chuyaoyao\Downloads\AppiumForWindows\Appium\node_modules\appium\lib\helpers
.js:79:7)]
第二次运行 就报上一个错误了

#16 楼 @chuyaoyao 使用 1.0.0 就应该好了

解决没有呢,楼主


14 楼 @chuyaoyao 我也是相同的问题,解决了吗,如何解决的呢

@rockchensir 出现相同的问题 请问是怎么解决的呢?


public void setUp() throws MalformedURLException{

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("automationName", "Selendroid");

capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("platformVersion", "4.0");
capabilities.setCapability("platform", "WINDOWS");
capabilities.setCapability("keystorePath", "C:\apps\android.keystore");
capabilities.setCapability("keystorePassword", "android");

capabilities.setCapability("app", "C:\apps\sh_android_2.8.3.apk");
capabilities.setCapability("appPackage", "com.acheo.aohehop");
capabilities.setCapability("appActivity", ".activity.LodingActivity");

求指导

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册