Appium 【已解决】appium 运行模拟器的测试 apk 运行报错

· 2015年05月18日 · 最后由 扮猪吃老虎 回复于 2015年05月20日 · 1134 次阅读

各位大神,我运行 genymotion 模拟器的 apk 运行报错。
我的配置脚本为

#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.157: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() #测试报告关闭


运行后 appium 控制台的 error 如下:

> Starting Node Server
> info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
> info: Appium REST http interface listener started on 192.168.10.157:4723
> info: [debug] Non-default server args: {"address":"192.168.10.157","logNoColors":true,"deviceName":"192.168.56.101:5555","platformName":"Android","platformVersion":"18","automationName":"Appium"}
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session {"desiredCapabilities":{"appActivity":".DialtactsActivity","platformName":"Android","platformVersion":"4.3","deviceName":"192.168.56.101:5555","appPackage":"com.android.dialer"}}
> info: Client User-Agent string: Python-urllib/3.4
> 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 064cdc4a-eb89-47fa-8f68-ef127b3eec32
> 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] Not checking whether app is present since we are assuming it's already on the device
> 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] Retrying restartAdb
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 devices
> info: [debug] 1 device(s) connected
> 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] Retrying restartAdb
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 kill-server
> error: Error killing ADB server, going to see if it's online anyway
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: D:\BaiduYunDownload\android-sdk\platform-tools\adb.exe -s 192.168.56.101:5555 devices
> Killed Node Server.
> Node Server Process Ended

反复的 [debug] Retrying restartAdb,有大神指点么~

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

为啥我感觉你的发帖都是一模一样呢?

#2 · 2015年05月18日 Author

#1 楼 @lihuazhang 脚本么。。。是啊,我没用命令行,用那个 winform 程序的,各种蛋疼问题~

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

你检查下 appium 设置的端口是否正确,这里报错说找不到设备

#4 · 2015年05月18日 Author

#3 楼 @app_testing 正确的,有时候就会出现这个问题~

desired_caps['deviceName'] = '192.168.56.101:5555'

这是啥玩意儿,不应该配置模拟器吗

#6 · 2015年05月21日 Author

#5 楼 @sunrise 这就是模拟器啊。。。

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