公共文件healthcommon.py放在test_case下
用例的层级结构为 –test_case
-test_dir
tc1.py
- healthcommon.py
登录模块化报错“AttributeError: ‘TestCommon’object has no attribute ‘driver’;”
Login使用的是self.driver,self表示当前类下面有的变量/对象,driver参数根本没用到,
虫师告诉把上面的self去掉之后,调试就可以了。
common.py代码
class TestCommon():
def login(self, driver):
# def login(self):
login = "12345678907"
# login = "12341111133"
# login = "18102128737"
# pwd = "123456"
# pwd = "333333"
pwd = "888888"
driver.find_element_by_id('account_edit').clear()
driver.find_element_by_id('account_edit').send_keys(login)
driver.find_element_by_id('password_edit').clear()
driver.find_element_by_id('password_edit').send_keys(pwd)
driver.find_element_by_id('login_button').click()
driver.implicitly_wait(8)
def logout(self, driver):
driver.implicitly_wait(8)
driver.find_element_by_id('my_center').click()
driver.find_element_by_android_uiautomator('text("设置")').click()
driver.find_element_by_id('exit_btn').click()
driver.find_element_by_id('android:id/button1').click()
driver.implicitly_wait(3)
driver.close_app()
非common用例tc1部分代码
import os,time,unittest
from appium import webdriver
from HTMLTestRunner import HTMLTestRunner
from selenium.webdriver.support.ui
import WebDriverWait
from selenium.webdriver.support
import expected_conditions
as EC
# from selenium.common
import exceptions as EX
from appium.common import exceptions as EX
from test_case.healthcommon
import TestCommon
class TestASCVDResult(unittest.TestCase):
def setUp(self):
print("风险评估结果测试开始...")
PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__),p))
desired_caps = {}
desired_caps = {'platform':'Android',
#
'platformVersion':'5.1.1',
#
'deviceName':'T1_823L',
# 'platformVersion':'Android
6.0',
#
'deviceName':'HUAWEI VNS-AL00',
#
'platformVersion':'8.1.0',
#
'deviceName':'OPPO R15',
#
'platformVersion':'9',
# 'deviceName':'Honor 8X',
'platformVersion': 'Android 5.1.1',
'deviceName': 'Redmi 3',
'platformVersion': 'Android 5.1',
'deviceName': 'Note2',
'platformVersion': '7.0',
'deviceName': 'Galaxy S6 edge',
'platformVersion': '7.1.2',
'deviceName': 'vivo X9',
'app':PATH(r"E:apptestOrangerFamily.apk"),
'appPackage': 'com.chengyifamily.patient',
'appActivity': 'com.chengyifamily.patient.SplashActivity',
'noReset': True,
'unicodeKeyboard': True,
'resetKeyboard': True,
'autoAcceptAlerts': True
}
self.driver = webdriver.Remote("http://localhost:4723/wd/hub",desired_caps)
self.driver.implicitly_wait(3)
TestCommon().login(self.driver)
def tearDown(self):
TestCommon().logout(self.driver)