uiautomator2 | Android Uiautomator2 Python Wrapper

 by   openatx Python Version: 3.1.0 License: MIT

kandi X-RAY | uiautomator2 Summary

kandi X-RAY | uiautomator2 Summary

uiautomator2 is a Python library. uiautomator2 has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install uiautomator2' or download it from GitHub, PyPI.

UiAutomator是Google提供的用来做安卓自动化测试的一个Java库,基于Accessibility服务。功能很强,可以对第三方App进行测试,获取屏幕上任意一个APP的任意一个控件属性,并对其进行任意操作,但有两个缺点:1. 测试脚本只能使用Java语言 2. 测试脚本要打包成jar或者apk包上传到设备上才能运行。. 我们希望测试逻辑能够用Python编写,能够在电脑上运行的时候就控制手机。这里要非常感谢 Xiaocong He (@xiaocong),他将这个想法实现了出来(见xiaocong/uiautomator),原理是在手机上运行了一个http rpc服务,将uiautomator中的功能开放出来,然后再将这些http接口封装成Python库。 因为xiaocong/uiautomator这个库,已经很久不见更新。所以我们直接fork了一个版本,为了方便做区分我们就在后面加了个2 openatx/uiautomator2. 这里要先说明下,因为经常有很多人问 openatx/uiautomator2 并不支持iOS测试,需要iOS自动化测试,可以转到这个库 openatx/facebook-wda。. PS: 这个库 ~~目前已经不维护了,请尽快更换。. 这里有一份快速参考,适合已经入门的人 QUICK REFERENCE GUIDE,欢迎多提意见。.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              uiautomator2 has a medium active ecosystem.
              It has 5204 star(s) with 1252 fork(s). There are 191 watchers for this library.
              There were 1 major release(s) in the last 6 months.
              There are 323 open issues and 464 have been closed. On average issues are closed in 81 days. There are 5 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of uiautomator2 is 3.1.0

            kandi-Quality Quality

              uiautomator2 has 0 bugs and 0 code smells.

            kandi-Security Security

              uiautomator2 has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              uiautomator2 code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              uiautomator2 is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              uiautomator2 releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              uiautomator2 saves you 2255 person hours of effort in developing the same functionality from scratch.
              It has 4931 lines of code, 476 functions and 35 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed uiautomator2 and discovered the below as its top functions. This is intended to give you an instant insight into uiautomator2 implemented functionality, and help decide if they suit your requirements.
            • Capture screenshot
            • Execute a shell command
            • Return the orientation of the display
            • Get window size
            • Convert csv to images
            • Return a human readable size
            • Run a configuration file
            • Run a single step
            • Start an application
            • Finds an image matching the given image search criteria
            • Run a step
            • Parse a step
            • Install Android
            • Compares two images and compares them using comparison
            • Read image data
            • Returns a human readable size
            • Return the parent of this element
            • Send keyboard keys
            • Continuously collect metrics
            • Connect to a device
            • Make a HTTP request
            • Create a new touch
            • Prints the documentation of the device
            • Compare two nodes
            • Creates a new abort abort message
            • Return the current active window
            • Start the screen
            • Scroll to xpath
            Get all kandi verified functions for this library.

            uiautomator2 Key Features

            No Key Features are available at this moment for uiautomator2.

            uiautomator2 Examples and Code Snippets

            uiautomator2 init for atx-server,REST API (设计中)
            Godot img1Lines of Code : 56dot img1License : Permissive (MIT)
            copy iconCopy
            GET $SERVER_URL/devices
            
            {
                "success": true,
                "data": [
                    {"serial": "3ffecdf", "product": "MHA-AL00", "model": "MHA_AL00", "device": "HWMHA"},
                    {"serial": "6EB0217607006479", "product": "DUK-AL20", "model": "DUK_AL20", "device": "  
            uiautomator2 init for atx-server,Installation
            Godot img2Lines of Code : 6dot img2License : Permissive (MIT)
            copy iconCopy
            $ go get -v github.com/openatx/u2init
            $ cd $GOPATH/src/github.com/openatx/u2init
            $ go build
            
            # download stf stuffs(minitouch, minicap), uiautomator.apk(two apk actually)
            $ ./init-resources.sh
              
            copy iconCopy
            $ ./u2init --server 10.0.0.1:8000 --initd > /etc/init.d/u2init # server addr should be modified
            $ update-rc.d u2init defaults 90 # 启动级别90
              
            uiautomator2 - run
            Pythondot img4Lines of Code : 115dot img4License : Permissive (MIT License)
            copy iconCopy
            #!/usr/bin/env python3
            # coding: utf-8
            #
            
            import re
            import os
            import time
            import argparse
            
            import yaml
            import bunch
            import uiautomator2 as u2
            from logzero import logger
            
            
            CLICK = "click"
            # swipe
            SWIPE_UP = "swipe_up"
            SWIPE_RIGHT = "swipe_right"
            SWIPE  
            uiautomator2 - main
            JavaScriptdot img5Lines of Code : 52dot img5License : Permissive (MIT License)
            copy iconCopy
            'use strict'
            
            var Promise = require('bluebird')
            var adb = require('adbkit')
            var client = adb.createClient()
            var util = require('util')
            const { spawn } = require("child_process")
            var argv = require('minimist')(process.argv.slice(2))
            
            const serverAddr   
            uiautomator2 - minitouch
            Pythondot img6Lines of Code : 36dot img6License : Permissive (MIT License)
            copy iconCopy
            # coding: utf-8
            #
            # 半成品
            import json
            from . import Device
            from websocket import create_connection
            
            
            class Minitouch:
                # TODO: need test
                def __init__(self, d: Device):
                    self._d = d
                    self._prepare()
            
                def _prepare(self):
                      

            Community Discussions

            QUESTION

            starting Appium in port 4723 redirects to port 8200
            Asked 2022-Mar-01 at 02:19

            Currently I am starting programmatically an Appium server with the following capabilities

            ...

            ANSWER

            Answered 2022-Mar-01 at 02:19

            I've noticed a lot of weird behaviour when connecting to the loopback address (0.0.0.0), so it might be related to that.

            Try starting Appium by explicitly binding to localhost, which you can do with the --address argument, eg --address 127.0.0.1.

            Then, update your connection string to http://127.0.0.1:4723/wd/hub.

            Source https://stackoverflow.com/questions/71257549

            QUESTION

            Explicit wait utility
            Asked 2022-Feb-09 at 09:08

            I am using one generic explicit wait utility which can be used in different places in my test case. Following is the code I have written for the same under Base Test. Here I am looking for a text to present in the screen.For that I have given the parameter "text" in the function VerifyTextPresence.

            But after running the script, I am having the below error. How to make it generic so that for any text, I can use this utility. For example, here I am checking for the text "Get" to be present in the screen

            Utility Code:

            ...

            ANSWER

            Answered 2022-Feb-09 at 09:08

            QUESTION

            How to avoid killing the running application when starting the Appium Inspector session?
            Asked 2022-Jan-31 at 14:09

            I would like to launch Appium Inspector session to attach to the currently running Android app on my device. The problem I'm facing is that whenever I start the session, the running app is getting killed and launched again. Is there any way to avoid that?

            I'm currently using the following config:

            ...

            ANSWER

            Answered 2022-Jan-31 at 14:09

            Not sure, but those capabilities might help:

            Source https://stackoverflow.com/questions/70907704

            QUESTION

            Why swipe doesn't work with appium on Android[React-Native]?
            Asked 2022-Jan-20 at 15:54

            I'm trying to make swipe by coordinates (x/y) I have found this method on the appium webite, but it doesn't work for me and shows this error: TypeError: Cannot read property 'performTouchAction' of undefined

            This is my test's code:

            ...

            ANSWER

            Answered 2022-Jan-20 at 15:54

            I have found such solution:

            Source https://stackoverflow.com/questions/70774191

            QUESTION

            Run Chrome on emulator with appium?
            Asked 2021-Nov-07 at 18:53

            I have somme issues when I am trying to run Chrome on emulator device with appium. I am pretty sure that Chrome is not installed on my emulator, but not 100% sure that is the case, and if it is how to fix it.

            Currently mu Appim server logs looks like:

            ...

            ANSWER

            Answered 2021-Nov-07 at 18:53

            If Appium cannot find the application, It tries to install it on the device. So it is important to add the App variable in your desired capabilities with the location of the APK file. This line shows that Appium tried to install the chrome on the device but couldn't find the APP variable in the Caps.

            Encountered internal error running the command: Error: 'app' option is required for reinstall

            Just add this to your caps:

            cap.setCapability(MobileCapabilityType.APP, "APK PATH OF CHROME");

            Source https://stackoverflow.com/questions/69679964

            QUESTION

            How to find an element by mobile xpath with Appium matching @text attribute with a regular expression (regex)?
            Asked 2021-Oct-08 at 17:18

            I'm automating Android apps using Selenium-Appium (Java) and I got some difficult to address the following need:

            I have an element that doesn't have any of ID or ACCESSIBILITY ID configured. But I've noticed that its value is a fixed pattern, a date, like "dd/MM/yyyy".

            So, I need “to get element in screen which pattern fits with ‘dd/MM/yyyy’ date pattern”. How am I supposed to achieve it?

            I’d tried to call:

            ...

            ANSWER

            Answered 2021-Oct-07 at 22:01

            matches keyword can be used with xpath 2.0. I was not able to find online which version does the appium client app use, but you can implement an intermediary solution with java core:

            First find all the elements that contain slash

            Source https://stackoverflow.com/questions/69486336

            QUESTION

            Cannot call setValue for element using Appium, Javascript and webdriverio
            Asked 2021-Sep-01 at 07:32

            I am using Appium, UIAutomator2, webdriverio and JavaScript to test an app which is running on a virtual device.

            I search for an element and set (or in this case clear) its value.

            Using class selector it works fine.

            ...

            ANSWER

            Answered 2021-Sep-01 at 07:32

            For some reason the webdriverio is not able to resolve the retrieved element correctly when I use findElement("id", ...) or findElement("xpath", ...). As I would like to address the element by id resp. resource-id instead of the class, I could solve it by passing the resource-id using xpath syntax

            Source https://stackoverflow.com/questions/68999974

            QUESTION

            How can i get specific fileld from the Mongo DB
            Asked 2021-Aug-15 at 12:59

            I have written below code which is fetching 3 documents , from that document i want to display only specific filed excluding the other field

            ...

            ANSWER

            Answered 2021-Aug-15 at 12:59

            For official node.js MongoDB driver. The syntax for projection is like this

            Source https://stackoverflow.com/questions/68790943

            QUESTION

            Mobile app automation testing using Appium
            Asked 2021-Aug-06 at 10:49

            I am facing an error during the installation of Appium for mobile automation testing. I have installed android studio in drive G instead of C. When I start the session it shows the error below:

            An unknown server-side error occurred while processing the command. Original error:

            Cannot verify the signature of 'C:\Users\Thinkcenter\AppData\Local\Programs\Appium\resources \app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.21.1.apk'. Original error: Error: could not open `G:\androidsdk\platform-tools\lib\jvm.cfg'

            ...

            ANSWER

            Answered 2021-Aug-06 at 10:49

            The first thing that pops into my mind is setting up your environment variables correctly (does not do that automatically when installing Android Studio), but you may first want to debug your environment through appium-doctor.

            Option 1 Use NPM (Node.js package manager) to install appium-doctor globally from cmd:

            Source https://stackoverflow.com/questions/68679045

            QUESTION

            Not able to start activity using appium
            Asked 2021-Jul-15 at 11:31

            I am trying to launch a transparent activity using appium android driver and also passing some optional intent arguments. It is always failing with 500 status and the command times out no matter how much I set abdExecTimeout capability value.

            Sample code:

            ...

            ANSWER

            Answered 2021-Jul-15 at 11:31

            Figured out the reason. Appium by defaults adds -W to the adb command when startActivity is called which waits till the activity is launched. In my case it is a transparent activity and does not launch. So eventually the appium command times out and fails.

            Source https://stackoverflow.com/questions/68305135

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install uiautomator2

            运行pip3 install -U uiautomator2 安装uiautomator2. 运行python3 -m uiautomator2 init安装包含httprpc服务的apk到手机+atx-agent, minicap, minitouch (在过去的版本中,这一步是必须执行的,但是从1.3.0之后的版本,当运行python代码u2.connect()时就会自动推送这些文件了).
            Install weditor (UI Inspector). Install daemons to a device (Optional).
            Install uiautomator2 # Since uiautomator2 is still under development, you have to add --pre to install the development version pip install --upgrade --pre uiautomator2 # Or you can install directly from github source git clone https://github.com/openatx/uiautomator2 pip install -e uiautomator2 测试是否安装成功 uiautomator2 --help
            Install weditor (UI Inspector) 因为uiautomator是独占资源,所以当atx运行的时候uiautomatorviewer是不能用的,为了减少atx频繁的启停,我们开发了基于浏览器技术的weditor UI查看器。https://github.com/openatx/weditor 安装方法(备注: 目前最新的稳定版为 0.1.0) pip install -U weditor 安装好之后,就可以在命令行运行weditor --help 确认是否安装成功了。 Windows系统可以使用命令在桌面创建一个快捷方式 weditor --shortcut 命令行直接输入 weditor 会自动打开浏览器,输入设备的ip或者序列号,点击Connect即可。 具体参考文章:浅谈自动化测试工具python-uiautomator2
            Install daemons to a device (Optional) 电脑连接上一个手机或多个手机, 确保adb已经添加到环境变量中,执行下面的命令会自动安装本库所需要的设备端程序:uiautomator-server 、atx-agent、openstf/minicap、openstf/minitouch # init 所有的已经连接到电脑的设备 python -m uiautomator2 init # 高阶用法 # init and set atx-agent listen in all address python -m uiautomator2 init --addr :7912 有时候init也会出错,请参考手动Init指南 安装提示success即可
            【可选】AppetizerIO 所见即所得脚本编辑器 AppetizerIO 提供了对uiautomator2的深度集成,可以图形化管理ATX设备,还有所见即所得脚本编辑器 到网站下载直接打开,首次使用需要注册账号 设备管理 界面里可以检查设备是否正常init,起停atx-agent,抓取atx-agent.log文件 测试脚本调出脚本助手,实时界面同步,点击界面直接插入各种代码,同时支持uiautomator和Appium 视频教程 请戳这里 其他文档在此
            We only support installing an APK from a URL.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install uiautomator2

          • CLONE
          • HTTPS

            https://github.com/openatx/uiautomator2.git

          • CLI

            gh repo clone openatx/uiautomator2

          • sshUrl

            git@github.com:openatx/uiautomator2.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link