Best Python code snippet using Airtest
cv.py
Source:cv.py  
...121    #     image = self._resize_image(image, screen, ST.RESIZE_METHOD)122    #     ret = None123    #     for method in ST.CVSTRATEGY:124    #         if method == "tpl":125    #             ret = self._try_match(self._find_template, image, screen)126    #         elif method == "sift":127    #             ret = self._try_match(self._find_sift_in_predict_area, image, screen)128    #             if not ret:129    #                 ret = self._try_match(self._find_sift, image, screen)130    #         else:131    #             G.LOGGING.warning("Undefined method in CV_STRATEGY: %s", method)132    #         if ret:133    #             break134    #     return ret135    @logwrap136    def _cv_match(self, screen):137        # in case image file not exist in current directory:138        image = self._imread()139        ret = self._try_match(self._find_sift, image, screen)140        if not ret:141            G.LOGGING.warning("Undefined method in CV_STRATEGY: sift")142        return ret143    @staticmethod144    def _try_match(method, *args, **kwargs):145        G.LOGGING.debug("try match with %s" % method.__name__)146        try:147            ret = method(*args, **kwargs)148        except aircv.BaseError as err:149            G.LOGGING.debug(repr(err))150            return None151        else:152            return ret153    def _imread(self):154        return aircv.imread(self.filepath)155    def _find_all_template(self, image, screen):156        return aircv.find_all_template(screen, image, threshold=self.threshold, rgb=self.rgb)157    def _find_template(self, image, screen):158        return aircv.find_template(screen, image, threshold=self.threshold, rgb=self.rgb)...madness_stuffstuff.py
Source:madness_stuffstuff.py  
...95    ('^[az]+zx', 'aazx')96    """97    # Yet Another Insane Horror98    all_regexes = [regex[:idx] for idx in xrange(len(regex) + 1)]99    def _try_match(rex, st):100        try:101            return re.match(rex, st)102        except Exception:103            return104    # all_match_tries = [_try_match(subreg, s) for subreg in all_regexes]105    # Even more horrible:106    all_substrings = [value[:idx] for idx in xrange(len(value) + 1)]107    all_match_tries = (108        (subreg, _try_match(subreg, substr))109        for subreg in all_regexes110        for substr in all_substrings)111    all_matchstrings = [112        (subreg, val.group(0))113        for subreg, val in all_match_tries114        if val]115    if not all_matchstrings:116        return ''117    lrex, lval = max(118        all_matchstrings,119        key=lambda val: len(val[1]))  # longest match120    if return_regexp:121        return lrex, lval122    return lvalLearn 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!!
