標籤:form .com inf 路徑 自己的 pre key package info
py檔案的名稱為:appium_config.py 中的寫法如下
# coding=UTF-8‘‘‘Created on 2017.1.13@author: Lucky‘‘‘from appium import webdriverfrom Test.logs.logs import logging #本人自己封裝的方法,你們寫時可以不用調用,並且刪除方法中調用的logging即可class Singleton(object): driver = None def __new__(cls, *args, **kw): if not hasattr(cls, ‘_instance‘): orig = super(Singleton, cls) logging.info(‘-----------------------init driver----------------------‘) config = { ‘platformName‘:‘Android‘, ‘platformVersion‘:‘4.4‘, ‘deviceName‘:‘11111‘, ‘newCommandTimeout‘:30, ‘automationName‘:‘Appium‘, ‘appPackage‘:‘com.ibroker.iBerHK‘, ‘appActivity‘ :‘.SplashActivity‘ #‘autoLaunch‘:‘false‘ #appium是否要自動啟動或安裝APP,預設為ture #‘newCommandTimeout‘:‘60‘ #設定未接受到新命令的逾時時間,預設60s,說明:如果60s內沒有接收到新命令,appium會自動斷開,
如果我需要很長時間做driver之外的操作,可設定延長接收新命令的逾時時間 #‘unicodeKeyboard‘:True, #‘resetKeyboard‘:True #‘noReset‘:‘false‘ #在會話前是否重設APP狀態,預設是false } cls._instance = orig.__new__(cls, *args, **kw) cls._instance.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘,config) return cls._instance class DriverClient(Singleton): def getDriver(self): logging.info(‘get driver‘) return self.driver
針對此方法的調用,例如在py檔案為:Test_Driver_Elements.py中實現如上方法的調用,則寫法如下:
# coding=UTF-8‘‘‘Created on 2018.1.13@author: Lucky‘‘‘from Test.Common.appium_config import DriverClient #匯入appium_config.py,此處為我自己的路徑,你們根據自己的路徑寫即可from time import sleep
class test_Common: def __init__(self): driver = DriverClient().getDriver() self.device = Driver_Elements(driver) #對appium_config.py 檔案的調用 def Setting_MyCertification2(self): sleep(3) self.device.find_element_by_name("iiii").click() self.device.back(1)
若在其他的py檔案中需要則如上方法所示進行調用即可。
Python + Appium 【已解決】driver(session)在多個class之間複用,執行完一個類的用例,再次執行下個類的用例時不需要初始化