uiautomator2 | Android Uiautomator2 Python Wrapper
kandi X-RAY | uiautomator2 Summary
kandi X-RAY | uiautomator2 Summary
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
Top functions reviewed by kandi - BETA
- 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
uiautomator2 Key Features
uiautomator2 Examples and Code Snippets
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": "
$ 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
$ ./u2init --server 10.0.0.1:8000 --initd > /etc/init.d/u2init # server addr should be modified
$ update-rc.d u2init defaults 90 # 启动级别90
#!/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
'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
# 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
Trending Discussions on uiautomator2
QUESTION
Currently I am starting programmatically an Appium server with the following capabilities
...ANSWER
Answered 2022-Mar-01 at 02:19I'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
.
QUESTION
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:08Based on Appium docs
https://appium.io/docs/en/writing-running-appium/android/uiautomator-uiselector/
UiSelector for text should look like:
QUESTION
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:09Not sure, but those capabilities might help:
QUESTION
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:54I have found such solution:
QUESTION
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:53If 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");
QUESTION
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:01matches 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
QUESTION
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:32For 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
QUESTION
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:59For official node.js MongoDB driver. The syntax for projection is like this
QUESTION
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:49The 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:
QUESTION
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:31Figured 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.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install uiautomator2
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
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page