问答 appium + python 运行时报错 “AttributeError: 'xxxx' object has no attribute 'driver'”

End · 2017年03月23日 · 最后由 房超 回复于 2020年04月20日 · 233 次阅读

问题: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
共收到 5 条回复 时间 点赞
End #1 · 2017年03月23日 Author

有遇到这个问题么,求解决

这个是语法错误啊。。。 driver 的确没有啊。。

End 回复

楼主你这个问题解决了嘛?

setUp, Up 这个要大写

一语道破

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