# How to use safe_xy method in Airtest

Best Python code snippet using Airtest

resolution.py

Source:resolution.py

`...22 res_x, res_y = src_resolution23 else:24 res_y, res_x = im_source.shape[:2]25 prePos_x, prePos_y = clk_x * res_x + 0.5 * res_x, clk_y * res_x + 0.5 * res_y26 def safe_xy(val, min_val, max_val):27 return min(max(min_val, val), max_val)28 # åä»¥é¢æµç¹ä¸ºä¸­å¿ï¼è¿è¡èå´æå:29 start_x = int(safe_xy(prePos_x - radius_x, 0, res_x - 1))30 end_x = int(safe_xy(prePos_x + radius_x, 0, res_x - 1))31 start_y = int(safe_xy(prePos_y - radius_y, 0, res_y - 1))32 end_y = int(safe_xy(prePos_y + radius_y, 0, res_y - 1))33 # å¦æåç°é¢æµåºåå®å¨å¨å¾åå¤ï¼é¢æµåºåå°åªå©ä¸ä¸æ¡åç´ ï¼é¢æµå¤±è´¥ï¼ç´æ¥raise:34 if start_x == end_x or start_y == end_y:35 img_src, left_top_pos = im_source, (0, 0)36 log_info = "Predict area's width or height has just one pixel, abandon prediction."37 else:38 # é¢æµåºåæ­£å¸¸ï¼åæªåé¢æµåºåï¼å¹¶å°é¢æµåºåå¨æºå¾åä¸­çä½ç½®ä¸å¹¶è¿å:39 img_src = im_source[start_y:end_y, start_x:end_x]40 left_top_pos = (start_x, start_y)41 # è¾åºè°è¯ä¿¡æ¯.42 log_info = "predict rect: X (%(start_x)s:%(end_x)s) Y (%(start_y)s:%(end_y)s)" % {"start_x": start_x, "end_x":end_x, "start_y": start_y, "end_y": end_y}...`

## Automation Testing Tutorials

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.