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
包导入的有问题吧 https://blog.csdn.net/libertine1993/article/details/54232474/参考下这篇文章 来学习 def setUP(self):
还是def setUp(self):{:4_97:} 写的有问题吧
页:
[1]