Best Python code snippet using Airtest
android.py
Source:android.py
...112 """113 warnings.warn("No need to manually specify cap_method, airtest will automatically specify a suitable screenshot method, when airtest>=1.1.2")114 self.screen_proxy = name115 @property116 def screen_proxy(self):117 """118 Similar to touch_proxy, it returns a proxy that can automatically initialize an available screenshot method, such as Minicap119 Afterwards, you only need to call ``self.screen_proxy.get_frame()`` to get the screenshot120 类似touch_proxyï¼è¿åä¸ä¸ªä»£çï¼è½å¤èªå¨åå§åä¸ä¸ªå¯ç¨çå±å¹æªå¾æ¹æ³ï¼ä¾å¦Minicap121 åç»åªéè¦è°ç¨ ``self.screen_proxy.get_frame()``å³å¯è·åå°å±å¹æªå¾122 Returns: ScreenProxy(Minicap())123 Examples:124 >>> dev = Android()125 >>> img = dev.screen_proxy.get_frame_from_stream() # dev.minicap.get_frame_from_stream() is deprecated126 """127 if self._screen_proxy:128 return self._screen_proxy129 self._screen_proxy = ScreenProxy.auto_setup(self.adb, default_method=self._cap_method,130 rotation_watcher=self.rotation_watcher,131 display_id=self.display_id,132 ori_function=lambda: self.display_info)133 return self._screen_proxy134 @screen_proxy.setter135 def screen_proxy(self, cap_method):136 """137 Specify a screenshot method, if the method fails to initialize, try to use other methods instead138 æå®ä¸ä¸ªæªå¾æ¹æ³ï¼å¦æ该æ¹æ³åå§å失败ï¼åå°è¯ä½¿ç¨å
¶ä»æ¹æ³ä»£æ¿139 Args:140 cap_method: "MINICAP" or :py:mod:`airtest.core.android.cap_methods.minicap.Minicap` object141 Returns:142 ScreenProxy object143 Raises:144 ScreenError when the connection fails145 Examples:146 >>> dev = Android()147 >>> dev.screen_proxy = "MINICAP"148 >>> from airtest.core.android.cap_methods.minicap import Minicap149 >>> minicap = Minicap(dev.adb, rotation_watcher=dev.rotation_watcher)...
screenshot.py
Source:screenshot.py
1"""2 Copyright © 2017 Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>3 This file is part of Authenticator.4 Authenticator is free software: you can redistribute it and/or5 modify it under the terms of the GNU General Public License as published6 by the Free Software Foundation, either version 3 of the License, or7 (at your option) any later version.8 Authenticator is distributed in the hope that it will be useful,9 but WITHOUT ANY WARRANTY; without even the implied warranty of10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11 GNU General Public License for more details.12 You should have received a copy of the GNU General Public License13 along with Authenticator. If not, see <http://www.gnu.org/licenses/>.14"""15from os import path16from tempfile import NamedTemporaryFile17from gi.repository import Gio, GLib18class GNOMEScreenshot:19 """20 GNOME Screenshot interface implementation.21 Currently implements the only needed method by Authenticator.22 """23 interface = "org.gnome.Shell.Screenshot"24 path = "/org/gnome/Shell/Screenshot"25 def __init__(self):26 pass27 @staticmethod28 def area(filename: str = None) -> str:29 """30 Take a screen shot of an area and save it to a specific filename31 Using GNOME Shell Screenshot Interface.32 :param filename: output filename33 :type filename: str34 """35 if not filename:36 filename = path.join(GLib.get_user_cache_dir(),37 path.basename(NamedTemporaryFile().name))38 bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)39 screen_proxy = Gio.DBusProxy.new_sync(bus,40 Gio.DBusProxyFlags.NONE,41 None,42 GNOMEScreenshot.interface,43 GNOMEScreenshot.path,44 GNOMEScreenshot.interface,45 None)46 x, y, width, height = screen_proxy.call_sync('SelectArea', None, Gio.DBusCallFlags.NONE,47 -1, None).unpack()48 args = GLib.Variant('(iiiibs)', (x, y, width, height, False, filename49 )50 )51 screenshot = screen_proxy.call_sync('ScreenshotArea', args,52 Gio.DBusCallFlags.NONE, -1, None)53 success, filename = screenshot.unpack()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!