问题:appium + python 运行时报错 “AttributeError: 'xxxx' object has no attribute 'driver'”,刚接触自动化测试,请社区大神指导!

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import unittest
from appium import webdriver

PATH = lambda p : os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

class FmTest(unittest.TestCase):
#    driver = None

#    def __init__(self, appium_driver):
#       self.driver = appium_driver

    def setUP(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.4.4'
        desired_caps['deviceName'] = 'Android Emulator'
#        desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')
        desired_caps['appPackage'] = 'cn.thecover.www.covermedia'
        desired_caps['appActivity'] = 'cn.thecover.www.covermedia.ui.activity.SplashActivity'

        self.driver = webdriver.Remote('http://127.0.0.1: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('cn.thecover.www.covermedia:id/tab_name').click()

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(FmTest)
    unittest.TextTestRunner(verbosity=2).run(suite)

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/TestSty/fm_appiumtest/mypage.py
test_add_contacts (__main__.FmTest) ... ERROR
ERROR

======================================================================
ERROR: test_add_contacts (__main__.FmTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/TestSty/fm_appiumtest/mypage.py", line 34, in test_add_contacts
    self.driver.find_element_by_id('cn.thecover.www.covermedia:id/tab_name').click()
AttributeError: 'FmTest' object has no attribute 'driver'

======================================================================
ERROR: test_add_contacts (__main__.FmTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/TestSty/fm_appiumtest/mypage.py", line 31, in tearDown
    self.driver.quit()
AttributeError: 'FmTest' object has no attribute 'driver'

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=2)

Process finished with exit code 0


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