Best Python code snippet using Airtest
cv.py
Source: cv.py
...98 return focus_pos99 def match_all_in(self, screen):100 image = self._imread()101 image = self._resize_image(image, screen, ST.RESIZE_METHOD)102 return self._find_all_template(image, screen)103 def _cv_match(self, screen):104 # in casePackage image file not exist in current directory:105 if isinstance(self.filepath, type('')):106 image = self._imread()107 else:108 image = self.filepath109 if isinstance(image, unicode):110 image = aircv.imread(image)111 if self.is_image_cut:112 image = self.image_cut(image)113 if isinstance(screen, type('')):114 screen = aircv.imread(screen)115 screen = self.image_cut(screen)116 image = self._resize_image(image, screen, ST.RESIZE_METHOD)117 ret = None118 for method in ST.CVSTRATEGY:119 if method == "tpl":120 ret = self._try_match(self._find_template, image, screen)121 print 'find_template**********'122 print ret123 elif method == "sift" and self.sift:124 ret = self._try_match(self._find_sift_in_predict_area, image, screen)125 print 'find_sift_in_predict_area**********'126 print ret127 if not ret:128 ret = self._try_match(self._find_sift, image, screen)129 print 'find_sift**********'130 print ret131 else:132 # G.LOGGING.warning("Undefined method in CV_STRATEGY: %s", method)133 pass134 if ret:135 break136 return ret137 @staticmethod138 def image_cut(image):139 height, width, channels = image.shape140 return image[int(height/30):height, 0:width]141 @staticmethod142 def _try_match(method, *args, **kwargs):143 # G.LOGGING.debug("try match with %s" % method.__name__)144 try:145 ret = method(*args, **kwargs)146 except aircv.BaseError as err:147 # G.LOGGING.debug(repr(err))148 return None149 else:150 return ret151 def _imread(self):152 return aircv.imread(self.filepath)153 def _find_all_template(self, image, screen):154 return aircv.find_all_template(screen, image, threshold=self.threshold, rgb=self.rgb)155 def _find_template(self, image, screen):156 return aircv.find_template(screen, image, threshold=self.threshold, rgb=self.rgb)157 def _find_sift(self, image, screen):158 return aircv.find_sift(screen, image, threshold=self.threshold, rgb=self.rgb)159 def _find_sift_in_predict_area(self, image, screen):160 if not self.record_pos:161 return None162 # calc predict area in screen163 screen_resolution = aircv.get_resolution(screen)164 xmin, ymin, xmax, ymax = Predictor.get_predict_area(self.record_pos, screen_resolution)165 # crop predict image from screen166 predict_area = aircv.crop_image(screen, (xmin, ymin, xmax, ymax))167 # aircv.show(predict_area)...
template.py
Source: template.py
...59 def match_all_in(self, screen, in_rect=None):60 image = self._imread()61 image = self._resize_image(image, screen, ST.RESIZE_METHOD)62 if in_rect is None:63 results = self._find_all_template(image, screen)64 else:65 pos_left_top = (int(in_rect[0][0] * screen.shape[1] / 2 + screen.shape[1] / 2),66 int(in_rect[0][1] * screen.shape[0] / 2 + screen.shape[0] / 2))67 pos_right_bottom = (int(in_rect[1][0] * screen.shape[1] / 2 + screen.shape[1] / 2),68 int(in_rect[1][1] * screen.shape[0] / 2 + screen.shape[0] / 2))69 img_part = screen[pos_left_top[1]: pos_right_bottom[1], pos_left_top[0]: pos_right_bottom[0]]70 results = self._find_all_template(image, img_part)71 if results is not None:72 for result in results:73 result['result'] =(result['result'][0] + pos_left_top[0], result['result'][1] + pos_left_top[1])74 rectangle = ((result["rectangle"][0][0] + pos_left_top[0], result["rectangle"][0][1] + pos_left_top[1]),75 (result["rectangle"][1][0] + pos_left_top[0], result["rectangle"][1][1] + pos_left_top[1]),76 (result["rectangle"][2][0] + pos_left_top[0], result["rectangle"][2][1] + pos_left_top[1]),77 (result["rectangle"][3][0] + pos_left_top[0], result["rectangle"][3][1] + pos_left_top[1]))78 result["rectangle"] = rectangle79 if results is None:80 return {'results': None, 'feature': self, 'screen': screen}81 else:82 return {'results': results, 'feature': self, 'screen': screen}83 def get_image(self):84 return self._imread()85 def get_caller_module(self):86 return self._caller_module87 def _find_best_template(self, image, screen):88 return TemplateMatching(image, screen, threshold=self.threshold, rgb=self.rgb).find_best_result()89 def _find_all_template(self, image, screen):90 return TemplateMatching(image, screen, threshold=self.threshold, rgb=self.rgb).find_all_results()91 def _imread(self):92 if self._img is None:93 self._img = super(Template, self)._imread()...
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!