Python + Appium 【已解決】driver(session)在多個class之間複用,執行完一個類的用例,再次執行下個類的用例時不需要初始化

來源:互聯網
上載者:User

標籤: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之間複用,執行完一個類的用例,再次執行下個類的用例時不需要初始化

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.