我的代码:

#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])

请各位大神帮忙看看~


↙↙↙阅读原文可查看相关链接,并与作者交流