How to use safe_xy method in Airtest

Best Python code snippet using Airtest

resolution.py

Source:resolution.py Github

copy

Full Screen

...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}...

Full Screen

Full Screen

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful