51Testing软件测试论坛
标题:
appium + python 运行时报错 “AttributeError: 'xxxx' object has no attribute '...
[打印本页]
作者:
测试积点老人
时间:
2021-3-30 16:03
标题:
appium + python 运行时报错 “AttributeError: 'xxxx' object has no attribute '...
问题: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
复制代码
作者:
qqq911
时间:
2021-3-31 11:38
包导入的有问题吧
作者:
litingting0214
时间:
2021-3-31 16:09
https://blog.csdn.net/libertine1993/article/details/54232474/
参考下这篇文章
作者:
bellas
时间:
2021-3-31 16:15
来学习
作者:
郭小贱
时间:
2021-3-31 16:50
def setUP(self):
还是def setUp(self):
作者:
jingzizx
时间:
2021-3-31 17:25
写的有问题吧
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2