I work in a game company, as a test, the company uses Unity engine to develop games, so I will use some technologies to improve work efficiency, here I want to share with you.


Why use this technology?

  1. Convenient for later maintenance

    Reduce the amount of time spent maintaining automated use cases when planning changes to the game’s interface, greatly increasing efficiency

  2. Increased stability

    Because the screenshot is taken according to the element coordinates, the position of the screenshot is very accurate and can be controlled at will

Example code is as follows:

from GetID.GetDevice import serialno from airtest.core.api import * from airtest.aircv import * from poco.drivers.unity3d import UnityPoco class PartialScreenshot(): """ def __init__(self,devices): Self.devices = devices self.poco = UnityPoco() def get_phone_resolution(self): If g.david.display_info ['orientation'] in [1,3]: self.height = G.DEVICE.display_info['width'] self.width = G.DEVICE.display_info['height'] else: Display_info ['height'] self.width = g.depice. Display_info ['width'] # return the screen resolution self.height,self.width def crop_screenshot(self,elm,dvaluey1,dvaluex2,dvaluey2,dvaluex1): """ According to the coordinates of elements, the picture of the full-screen screenshot is cropped to achieve the effect of regional screenshot. :param elm: positioned element, that is, the area to be clipped :param dvaluey1: y axis minimum offset :param dvaluex2: X axis maximum offset :param dvaluey2: Y Max offset value :param dvaluex1: x min offset value :return: """ # getphone resolution self.get_phone_resolution() # getui element bounding box parameter. X_max =elm.get_bounds() Y1 = (bound[0]+dvaluey1) * self.height # y2 = (bound[1]+dvaluex2) * self.width # y2 = (bound[1]+dvaluex2) * self.width # y2 = (bound[3]+ dvaluey2) * self.height # left x1 = (bound[3]+dvaluex1) * self.width # left # Convert the data type of bounds to STR, if not STR, Y_min = STR (round(y1)) x_max = STR (round(x2)) y_max = STR (round(y2)) x_min = STR (round(x1)) screen = g.evpe.snapshot (quality=99) # crop_photo = Aircv. Crop_image (screen,(x_min,y_min,x_max,y_max)) # /Image/' # SavePath filename = 'partialscreenshot. JPG '# filename filepath = os.path.join(SavePath, Imwrite (filepath, crop_photo, 99) # Save the image if __name__ == '__main__': PSS = PartialScreenshot(serialno() pss.crop_screenshot(pss.poco("Windows").offspring("PickItemList").child("Viewport").child("Content").child("ItemBox(Clon E) "). The child (" Icon "), and 0,0,0,0)Copy the code