Appium 【已解决】appium 问题-运行 android native 拨号应用测试脚本报错

· 2015年05月12日 · 最后由 想飞的菜鸟 回复于 2015年08月20日 · 2045 次阅读

我的代码:

#coding=utf-8

import os
import unittest,sys,time,re,datetime,HTMLTestRunner
from appium import webdriver
from time import sleep
import sys
#reload(sys)
#sys.setdefaultencoding('utf-8')

# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

class ContactsAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.3'
        desired_caps['deviceName'] = '192.168.56.101:5555'
        desired_caps['appPackage'] = 'com.android.dialer'
        desired_caps['appActivity'] = '.DialtactsActivity'

        self.driver = webdriver.Remote('http://192.168.10.156:4723/wd/hub', desired_caps)

    def tearDown(self):
        self.driver.close_app()
        self.driver.quit()

    def test_add_contacts(self):
        self.driver.find_element_by_id('com.android.dialer:id/one').click()
        self.driver.find_element_by_xpath("//android.widget.ImageButton[contains(@content-desc,'退格')]").click()


if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(ContactsAndroidTests("test_add_contacts"))
    #suite.addTest(IposCase("testmaters"))
    timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
    filename = "D:\\appium\\appiumresult\\result_" + timestr + ".html"
    print (filename)
    fp = open(filename, 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream=fp,
                title='测试结果',
                description='测试报告'
                )
    #suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
    #unittest.TextTestRunner(verbosity=2).run(suite)
    runner.run(suite)
    #g_browser.quit()
    fp.close() #测试报告关闭

运行完了查看测试报告,发现错误:

ft1.1: Traceback (most recent call last):
  File "D:\appium\appiumtest3.py", line 25, in setUp
    self.driver = webdriver.Remote('http://192.168.10.156:4723/wd/hub', desired_caps)
  File "C:\Python34\lib\site-packages\appium\webdriver\webdriver.py", line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 74, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 123, in start_session
    'desiredCapabilities': desired_capabilities,
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 175, in execute
    self.error_handler.check_response(response)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Original error: Remote install failed: pkg: /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk

Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES])

Traceback (most recent call last):
  File "D:\appium\appiumtest3.py", line 25, in setUp
    self.driver = webdriver.Remote('http://192.168.10.156:4723/wd/hub', desired_caps)
  File "C:\Python34\lib\site-packages\appium\webdriver\webdriver.py", line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 74, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 123, in start_session
    'desiredCapabilities': desired_capabilities,
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 175, in execute
    self.error_handler.check_response(response)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: A new session could not be created. (Original error: Remote install failed: pkg: /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk

Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES])

请各位大神帮忙看看~

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 20 条回复 时间 点赞

Remote install failed: pkg: /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk

为啥还要安装啊?

#2 · 2015年05月12日 Author

#1 楼 @lihuazhang 恒温,阿拉也不晓得,报错是安装失败,但是我把 appname 删掉了啊

#2 楼 @mads 把 appium 的 log 也贴上来嘛。

➜  Desktop  python test.py
result_20150512111752.html
.
Time Elapsed: 0:00:06.288321
➜  Desktop

测试通过。和你的脚本一抹一眼,除了把退格改成了 backspace

#5 · 2015年05月12日 Author

#4 楼 @lihuazhang 改了还是不行。。应该跟 xpath 无关

#6 · 2015年05月12日 Author

#3 楼 @chenhengjie123 >

 info: --> POST /wd/hub/session {"desiredCapabilities":{"deviceName":"192.168.56.101:5555","platformVersion":"4.3","platformName":"Android","appPackage":"com.android.dialer","appActivity":".DialtactsActivity"}}
> info: Client User-Agent string: Python-urllib/3.4
> info: [debug] Using local app from command line: D:\appium\app-debug.apk
> info: [debug] Creating new appium session cd91dc70-fde3-4364-bb2b-931d050525e9
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_11
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Checking whether app is actually present
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device 192.168.56.101:5555
> info: [debug] Setting device id to 192.168.56.101:5555
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 wait-for-device
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 18
> info: Device API level is: 18
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "getprop persist.sys.language"
> info: [debug] Current device persist.sys.language: zh
> info: [debug] java -jar "E:\杞欢娴嬭瘯璧勬枡\AppiumForWindows-1.3.4.1_bak\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "D:\appium\app-debug.apk" "C:\Users\wuyuexin\AppData\Local\Temp\com.android.dialer" zh
> info: [debug] No strings.xml for language 'zh', getting default strings.xml
> info: [debug] java -jar "E:\杞欢娴嬭瘯璧勬枡\AppiumForWindows-1.3.4.1_bak\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "D:\appium\app-debug.apk" "C:\Users\wuyuexin\AppData\Local\Temp\com.android.dialer"
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 push "C:\\Users\\wuyuexin\\AppData\\Local\\Temp\\com.android.dialer\\strings.json" /data/local/tmp
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from D:\BaiduYunDownload\android-sdk\build-tools\18.0.0\aapt.exe
> info: [debug] Retrieving process from manifest.
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\build-tools\18.0.0\aapt.exe dump xmltree D:\appium\app-debug.apk AndroidManifest.xml
> info: [debug] Set app process to: com.android.dialer
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Checking app cert for D:\appium\app-debug.apk.
> info: [debug] executing cmd: java -jar E:\杞欢娴嬭瘯璧勬枡\AppiumForWindows-1.3.4.1_bak\Appium\node_modules\appium\node_modules\appium-adb\jars\verify.jar D:\appium\app-debug.apk
> info: [debug] App already signed.
> info: [debug] Zip-aligning D:\appium\app-debug.apk
> info: [debug] Checking whether zipalign is present
> info: [debug] Using zipalign from D:\BaiduYunDownload\android-sdk\tools\zipalign.exe
> info: [debug] Zip-aligning apk.
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\tools\zipalign.exe -f 4 D:\appium\app-debug.apk C:\Users\wuyuexin\AppData\Local\Temp\appium115412-6984-1w2yv1d.tmp
> info: [debug] MD5 for app is 43adfe9fcfc6677441d5aa5b07ab07df
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "ls /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk"
> info: [debug] Getting install status for com.android.dialer
> info: [debug] Getting device API level
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 18
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "pm list packages -3 com.android.dialer"
> info: [debug] App is not installed
> info: Installing App
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "mkdir -p /data/local/tmp/"
> info: [debug] Removing any old apks
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "ls /data/local/tmp/*.apk"
> info: [debug] Found an apk we want to keep at /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk
> info: [debug] Couldn't find any apks to remove
> info: [debug] Uninstalling com.android.dialer
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "am force-stop com.android.dialer"
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 uninstall com.android.dialer
> info: [debug] App was not uninstalled, maybe it wasn't on device?
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "pm install -r /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk"
> warn: Installing remote apk failed, going to uninstall and try again
> info: [debug] Removing any old apks
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "ls /data/local/tmp/*.apk"
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell rm "/data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk"
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 push "D:\\appium\\app-debug.apk" /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk
> info: [debug] Attempting to install again for the last time
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 shell "pm install -r /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> warn: UiAutomator did not shut down fast enough, calling it gone
> error: Failed to start an Appium session, err was: Error: Remote install failed: pkg: /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk
> 
> Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] Error: Remote install failed: pkg: /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk
> 
> Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]
>     at E:\杞欢娴嬭瘯璧勬枡\AppiumForWindows-1.3.4.1_bak\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1342:17
>     at null.<anonymous> (E:\杞欢娴嬭瘯璧勬枡\AppiumForWindows-1.3.4.1_bak\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:172:9)
>     at ChildProcess.exithandler (child_process.js:635:7)
>     at ChildProcess.EventEmitter.emit (events.js:98:17)
>     at maybeClose (child_process.js:743:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Remote install failed: pkg: /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk\r\r\nFailure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES])","origValue":"Remote install failed: pkg: /data/local/tmp/43adfe9fcfc6677441d5aa5b07ab07df.apk\r\r\nFailure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 20478.422 ms - 406 

帮忙看看,谢谢~

#5 楼 @mads 我意思是我这边可以运行的。你那边可能环境问题,或者你给的出错日志不对。

#8 · 2015年05月12日 Author

#7 楼 @lihuazhang 恩,我把 appium 端的报错日志贴了。最早贴的是 python 的报错

#8 楼 @mads 你把手机上 /data/local/tmp/ 这个目录清一下。
另外,日志请使用 代码块 格式。

#10 · 2015年05月12日 Author

#9 楼 @chenhengjie123 shell 这块不太会用,抽空学习一下。。。我是 genymotion 模拟器。。先谢了

#10 楼 @mads adb shell rm -rf /data/local/tmp/

#10 楼 @mads 能不能运行几个脚本后再一起输出测试报告?

#13 · 2015年05月28日 Author

#12 楼 @yuwuhen333 你详细描述下你的需求

#13 楼 @mads 我现在是一个 py 文件里面采用 appium 的 demo 写法写了一个方法,有 10 个 py,怎么把这几个运行的结果输出都在一个页面上呢

#15 · 2015年05月29日 Author

#14 楼 @yuwuhen333 10 个 py?每个都打个包,然后 import 到一个 py 中

#15 楼 @mads 10 个 py 下面不需要再写 if name == 'main':只需要在最后的一个执行这个就可以?谢谢

#17 · 2015年05月29日 Author

#16 楼 @yuwuhen333 main 就是默认全部运行了吧

#17 楼 @mads 采用了你说的方式,把要运行的 case 放在一个文件夹中,重新写一个脚本去读取该文件夹中的 py 文件,然后再输出到 html

#19 · 2015年05月29日 Author

#18 楼 @yuwuhen333 成功了不就行了,成功就不用跟我汇报了。。

个人觉得把中文路径换一下试试

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