在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Poco ポコA cross-engine UI automation framework. ExampleFirst you should connect your Android phone, for example, via usb cable and enable the ADB DEBUG MODE. # coding=utf-8import timefrom poco.drivers.unity3d import UnityPocopoco = UnityPoco()poco('btn_start').click()time.sleep(1.5)shell = poco('shell').focus('center')for star in poco('star'): star.drag_to(shell)time.sleep(1)assert poco('scoreVal').get_text() == "100", "score correct."poco('btn_back', type='Button').click() More examples here. Tools for writing test scriptsTo retrieve the UI hierarchy of the game, please use our AirtestIDE (an IDE for writing test scripts) orstandalone PocoHierarchyViewer (to view the hierarchy and attributes only but lightweight) ! InstallationIn order to use Poco, you must install Poco python library on your host and also install the poco-sdk inyour game/app. Poco can be installed straightforward with pip install pocoui SDK IntegrationFor poco-sdk integration please refer to Integration Guide Features
DocumentationUse poco on platforms/enginesThis section guide you how to start to use poco to write your test cases on different platforms/engines. Tutorials and examplesThis section will let your know all basic features of poco.
How to use PocoPoco supports different types of engines by different drivers. For different engines please initialize Following example shows how to initialize poco instance for
from poco.drivers.unity3d import UnityPocopoco = UnityPoco()# for unity editor on windows# poco = UnityPoco(('localhost', 5001), unity_editor=True)ui = poco('...')ui.click()
from poco.drivers.android.uiautomation import AndroidUiautomationPocopoco = AndroidUiautomationPoco()poco.device.wake()poco(text='Clock').click()
Working with Poco ObjectsBasic SelectorUI element objects can be selected by invoking The function takes one mandatory argument node name, the optional arguments can be substituted too and they refer tospecific node properties. For more information, refer to API Reference selecting UI. # select by node namepoco('bg_mission')# select by name and other propertiespoco('bg_mission', type='Button')poco(textMatches='^据点.*$', type='Button', enable=True) Relative SelectorWhen there is any ambiguity in the selected objects by node names/node types or object unable to select, the relativeselector tries to select the element object by hierarchy in following manner # select by direct child/offspringpoco('main_node').child('list_item').offspring('item') Sequence SelectorTree indexing and traversing is performed by default from up to down or from left to right. In case thatthe 'not-yet-traversed' nodes are removed from the screen, the exception is raised. The exception is not raised in casewhen the 'already-traversed' nodes are removed and in this case the traversing continues in previous order despitethe fact that the nodes in views were rearranged during the travers process. items = poco('main_node').child('list_item').offspring('item')print(items[0].child('material_name').get_text())print(items[1].child('material_name').get_text()) Iterate over a collection of objectsFollowing code snippet shows how to iterate over the collection of UI objects # traverse through every itemitems = poco('main_node').child('list_item').offspring('item')for item in items: item.child('icn_item') Get object propertiesFollowing examples shows how to obtain various properties of an object mission_btn = poco('bg_mission')print(mission_btn.attr('type')) # 'Button'print(mission_btn.get_text()) # '据点支援'print(mission_btn.attr('text')) # '据点支援' equivalent to .get_text()print(mission_btn.exists()) # True/False, exists in the screen or not Object Proxy Related OperationThis section describes object proxy related operations clickThe anchorPoint of UI element is attached to the click point by default. When the first argument(the relative click position) is passed to the function, the coordinates of the top-left corner of the bounding boxbecome Following example demonstrates how to use poco('bg_mission').click()poco('bg_mission').click('center')poco('bg_mission').click([0.5, 0.5]) # equivalent to centerpoco('bg_mission').focus([0.5, 0.5]).click() # equivalent to above expression swipeThe anchorPoint of UI element is taken as the origin, the swipe action is performed towards the given direction withthe certain distance. Following example shows how to use the joystick = poco('movetouch_panel').child('point_img')joystick.swipe('up')joystick.swipe([0.2, -0.2]) # swipe sqrt(0.08) unit distance at 45 degree angle up-and-rightjoystick.swipe([0.2, -0.2], duration=0.5) dragDrag from current UI element to the target UI element. Following example shows how to use the poco(text='突破芯片').drag_to(poco(text='岩石司康饼')) focus (local positioning)The anchorPoint is set as the origin when conducting operations related to the node coordinates. If the the local clickarea is need, the focus function can be used. The coordinate system is similar to the screen coordinates - the originis put to the top left corner of the bounding box and with length of unit of 1, i.e the coordinates of the center arethen poco('bg_mission').focus('center').click() # click the center The focus function can also be used as internal positioning within the objects. Following example demonstrates theimplementation of scroll operation in ScrollView. scrollView = poco(type='ScollView')scrollView.focus([0.5, 0.8]).drag_to(scrollView.focus([0.5, 0.2])) waitWait for the target objects to appear on the screen and return the object proxy itself. If the object exists, returnimmediately. poco('bg_mission').wait(5).click() # wait 5 seconds at most,click once the object appearspoco('bg_mission').wait(5).exists() # wait 5 seconds at most,return Exists or Not Exists Global OperationPoco framework also allows to perform the operations without any UI elements selected. These operations are calledglobal operations. clickpoco.click([0.5, 0.5]) # click the center of screenpoco.long_click([0.5, 0.5], duration=3) swipe# swipe from A to Bpoint_a = [0.1, 0.1]center = [0.5, 0.5]poco.swipe(point_a, center)# swipe from A by given directiondirection = [0.1, 0]poco.swipe(point_a, direction=direction) snapshotTake a screenshot of the current screen in base64 encoded string. The image format depends on the sdk implementation.Take a look at ScreenInterface.getScreen to dive into sdk implementation details. Note: from base64 import b64decodeb64img, fmt = poco.snapshot(width=720)open('screen.{}'.format(fmt), 'wb').write(b64decode(b64img)) ExceptionsThis sections describes the Poco framework errors and exceptions. PocoTargetTimeoutfrom poco.exceptions import PocoTargetTimeouttry: poco('guide_panel', type='ImageView').wait_for_appearance()except PocoTargetTimeout: # bugs here as the panel not shown raise PocoNoSuchNodeExceptionfrom poco.exceptions import PocoNoSuchNodeExceptionimg = poco('guide_panel', type='ImageView')try: if not img.exists(): img.click()except PocoNoSuchNodeException: # If attempt to operate inexistent nodes, an exception will be thrown pass Unit TestPoco is an automation test framework. For unit testing, please refer to PocoUnit section. PocoUnit provides a fullset of assertion methods and furthermore, it is also compatible with the Some ConceptsThis section describes some basic concepts of Poco. Basic terminology used in following section
Following images show the UI hierarchy represented in Poco Definitions of coordinate system and metric spaceNormalized Coordinate SystemIn normalized coordinate system, the origin (0, 0) lies on top left corner of the device display. The height and thewidth of the screen are chosen as 1 unit of length, refer to image below for more detailed information.In normalized coordinate system, the same UI elements on the devices with different resolution have always the sameposition and size. This is especially very handy when writing cross-device test cases. The space of normalized coordinate system is uniformly distributed, i.e. the coordinates of the screen center are(0.5, 0.5) and the computing method of other scalars and vectors are all same in Euclidean space. Local Coordinate System (local positioning)The aim of introducing local coordinate system is to express the coordinates with reference to a certain UI elements.The origin (0,0) of local coordinate system lies on the top left corner of UI bounding box, x-axis goes horizontallyrightward direction and y-axis goes vertically downwards. The height and the width of UI element are chosen as 1 unit oflength. Coordinates are expressed as signed distances from the origin. Other definitions are same as for normalizedcoordinate system. Local coordinate system is more flexible in order to locate the position within or outside of UI element, e.gthe coordinates at (0.5, 0.5) corresponds to the center of the UI element while coordinates larger than 1 or less than 0correspond to the position out of the UI element. Join to discuss!ContributionsAny pull requests are welcomed! We will have the code checked carefully. Please make sure the codes are compatible withpython 2/3 and have the same coding style. |
请发表评论