The name of the py file is: appium_config.py in the following notation
# coding=utf-8" "Created on2017.1. -@author: Lucky" " fromappium Import Webdriver fromTest.logs.logs Import Logging #本人自己封装的方法, you can write without calling and delete the logging called in the method classSingleton (Object): Driver= Nonedef __new__ (CLS, *args, * *kw):ifNot Hasattr (CLS,'_instance'): Orig=Super (Singleton, CLS) Logging.info ('-----------------------init driver----------------------') Config= { 'PlatformName':'Android', 'platformversion':'4.4', 'devicename':'11111', 'Newcommandtimeout': -, 'Automationname':'Appium', 'Apppackage':'Com.ibroker.iBerHK', 'appactivity':'. Splashactivity'# ' AutoLaunch ': ' false ' #appium是否要自动启动或安装APP, default to Ture # ' Newcommandtimeout ': ' $ ' #设置未接受到 Timeout for new command, default 60s, Description: If a new command is not received within 60s, Appium will automatically disconnect,
If I need a long time to do something other than driver, you can set the timeout to receive new commands # ' Unicodekeyboard ': true, # ' Resetkeyboard ': true # ' NoReset ': ' False ' #在会话前是否重置APP状态, the default is False } cls._instance= orig.__new__ (CLS, *args, * *kw) Cls._instance.driver= Webdriver. Remote ('Http://127.0.0.1:4723/wd/hub', config)returncls._instanceclassdriverclient (Singleton): def getdriver (self): Logging.info ('Get driver') returnSelf.driver
A call to this method, such as a call to the above method, is implemented in the Py file: test_driver_elements.py, as follows:
# coding=utf-8" "Created on2018.1.13@author: Lucky" " fromTest.Common.appium_config Import driverclient #导入appium_config. Py, here is my own path, you can write it according to your own path. From time import Sleep
classTest_common: def __init__ (self): driver=driverclient (). Getdriver () Self.device=driver_elements (Driver) #对appium_config. py file Call def setting_mycertification2 (self) : Sleep (3) Self.device.find_element_by_name ("IIII"). Click ()Self.device.back (1)
If required in other PY files, the call can be made as shown in the previous method.
Python + Appium "resolved" Driver (session) is reused between multiple classes, executes the use case of a class, and executes the next class's use case again without initialization