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

Source: Internet
Author: User
Tags appium

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.