Best Python code snippet using Airtest
ios.py
Source:ios.py  
...115            w, h = h, w116        return w, h117    def home(self):118        return self.driver.home()119    def _neo_wda_screenshot(self):120        """121            this is almost same as wda implementation, but without png header check,122            as response data is now jpg format in mid quality123        """124        value = self.driver.http.get('screenshot').value125        raw_value = base64.b64decode(value)126        return raw_value127    def snapshot(self, filename=None, strType=False, ensure_orientation=True):128        """129        take snapshot130        filename: save screenshot to filename131        """132        data = None133        if self.cap_method == CAP_METHOD.MINICAP:134            raise NotImplementedError135        elif self.cap_method == CAP_METHOD.MINICAP_STREAM:136            raise NotImplementedError137        elif self.cap_method == CAP_METHOD.WDACAP:138            data = self._neo_wda_screenshot()  # wda æªå¾ä¸ç¨èèæå139        # 宿¶å·æ°ææºç»é¢ï¼ç´æ¥è¿åbase64æ ¼å¼ï¼æè½¬é®é¢äº¤ç»IDEå¤ç140        if strType:141            if filename:142                with open(filename, 'wb') as f:143                    f.write(data)144            return data145        # output cv2 object146        try:147            screen = aircv.utils.string_2_img(data)148        except:149            # may be black/locked screen or other reason, print exc for debugging150            traceback.print_exc()151            return None152        h, w = screen.shape[:2]...iosfuncs.py
Source:iosfuncs.py  
...124            raise NotImplementedError125        elif self.cap_method == CAP_METHOD.MINICAP_STREAM:126            raise NotImplementedError127        elif self.cap_method == CAP_METHOD.WDACAP:128            data = self._neo_wda_screenshot()  # wda æªå¾ä¸ç¨èèæå129        if strType:130            if filename:131                with open(filename, 'wb') as f:132                    f.write(data)133            return data134        # output cv2 object135        try:136            screen = string_2_img(data)137        except:138            # may be black/locked screen or other reason, print exc for debugging139            import traceback140            traceback.print_exc()141            return None142        now_orientation = self.orientation143        # ensure the orientation is right144        if ensure_orientation and now_orientation in [LANDSCAPE, LANDSCAPE_RIGHT]:145            # minicap screenshots are different for various sdk_version146            if self.cap_method in (CAP_METHOD.MINICAP, CAP_METHOD.MINICAP_STREAM):147                h, w = screen.shape[:2]  # cvshapeæ¯é«åº¦å¨åé¢!!!!148                if w < h:  # å½åæ¯æ¨ªå±ï¼ä½æ¯å¾çæ¯ç«çï¼åæè½¬ï¼é对sdk<=16çæºå¨149                    screen = rotate(screen, self.display_info["orientation"] * 90, clockwise=False)150            # wda æªå¾æ¯è¦æ ¹æ®orientationæè½¬151            elif self.cap_method == CAP_METHOD.WDACAP:152                # seems need to rotate in opencv opencv-contrib-python==3.2.0.7153                screen = rotate(screen, 90, clockwise=(now_orientation == LANDSCAPE_RIGHT))154        # readed screen size155        h, w = screen.shape[:2]156        # save last res for portrait157        if now_orientation in [LANDSCAPE, LANDSCAPE_RIGHT]:158            self._size['height'] = w159            self._size['width'] = h160        else:161            self._size['height'] = h162            self._size['width'] = w163        winw, winh = self.window_size()164        self._touch_factor = float(winh) / float(h)165        # save as file if needed166        if filename:167            imwrite(filename, screen)168        return screen169    def _neo_wda_screenshot(self):170        """171            this is almost same as wda implementation, but without png header check,172            as response data is now jpg format in mid quality173        """174        value = self.driver.http.get('screenshot').value175        raw_value = base64.b64decode(value)176        return raw_value177    def _touch_point_by_orientation(self, tuple_xy):178        """179        Convert image coordinates to physical display coordinates, the arbitrary point (origin) is upper left corner180        of the device physical display181        Args:182            tuple_xy: image coordinates (x, y)183        Returns:...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!!
