Public documents healthcommon.py placed under test_case
Example of a hierarchy -test_case
-test_dir
tc1.py
- healthcommon.py
Login Modular error "AttributeError: 'TestCommon'object has no attribute' driver ';"
Login using self.driver, self represents the current class below some variables / objects, driver parameter no use to,
Mushishi told to get rid of after the above self, debugging it.
common.py Code
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()
Non-common part of the code used in Example 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:\apptest\OrangerFamily.apk"),
'appPackage': 'com.chengyifamily.patient',True ' Moresheth ':
appActivity ':' com.chengyifamily.patient.SplashActivity '
,
'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)
Like to thank Mushishi advice.