How to use uiautomator method in ATX

Best Python code snippet using ATX

uiautomator_manager.py

Source:uiautomator_manager.py Github

copy

Full Screen

...19_device_port=900820_uiautomator_port = os.environ.get("UIAUTOMATOR_PORT","19008")21def restartPlatformDialogHandler():22 try:23 kill_uiautomator()24 time.sleep(4) # wait for platform to relaunch uiautomator25 get_uiautomator().setdialogtextpattern(26 u'(^(完成|关闭|好|好的|确定|确认|安装|下次再说|暂不删除)$|(.*(?<!不|否)(忽略|允(\s)?许|同意)|继续|稍后|暂不|下一步).*)')27 get_uiautomator().setdialogtextgrouppattern(28 u'((建议.*清理)|是否卸载|卸载后)&&&(取消|以后再说|下载再说);是否发送错误报告&&&否;为了给您提供丰富的图书资源&&&取消;简化备份恢复流程&&&(以后再说|下次再说)')29 pkgfilter = ""30 if os.environ.get('PKGNAME'):31 pkgfilter = u'(?=(^(?!' + os.environ.get("PKGNAME") + u"$)))"32 get_uiautomator().setdialogpkgpattern(33 pkgfilter + u'^(?!(com.tencent.mm|com.tencent.mqq|com.tencent.mobileqq)$).*')34 get_uiautomator().setPermissionMonitor(True)35 time.sleep(1)36 except Exception as e:37 logger.exception(e)38def write_dialog_config(config_path):39 if os.environ.get("PKGNAME") is None:40 return41 content=""42 # with open(config_path,"r") as f:43 # content=f.read()44 textpattern=u'(^(完成|关闭|好|好的|确定|确认|安装|下次再说|暂不删除)$|(.*(?<!不|否)(忽略|允(\s)?许|同意)|继续|稍后|暂不|下一步).*)'45 textGroupPattern=u'((建议.*清理)|是否卸载|卸载后)&&&(取消|以后再说|下载再说);是否发送错误报告&&&否;为了给您提供丰富的图书资源&&&取消;简化备份恢复流程&&&(以后再说|下次再说)'46 pkgfilter=""47 if os.environ.get('PKGNAME'):48 pkgfilter = u'(?=(^(?!' + os.environ.get("PKGNAME") + u"$)))"49 pkgattern =pkgfilter + u'^(?!(com.tencent.mm|com.tencent.mqq|com.tencent.mobileqq)$).*'50 content += "textpattern=" + textpattern + "\n"51 content += "textGroupPattern=" + textGroupPattern + "\n"52 content += "pkgattern=" + pkgattern +"\n"53 content += "needDialogHandler=true" +"\n"54 with open(config_path, "w") as f:55 f.write(content)56def init_uiautomator_with_dialoghandler():57 """58 初始化uiautomator59 :return:60 """61 file_path = os.path.split(os.path.realpath(__file__))[0]62 uiautomator_stub_path = os.path.abspath(63 os.path.join(file_path,"..","third","libs","uiAutomator","DialogHandler_polling.jar"))64 #adb=AdbTool()65 config_path= os.path.abspath(66 os.path.join(file_path,"..","third","libs","uiAutomator","wetest_dialog_config.properties"))67 write_dialog_config(config_path)68 excute_adb_process("push {0} /data/local/tmp".format(uiautomator_stub_path))69 excute_adb_process("push {0} /data/local/tmp".format(config_path))70 excute_adb_process("shell am force-stop com.tencent.wetest.rc.rc_uiautomatorstub")71 kill_uiautomator()72 logger.debug("Start UIAutomator")73 #os.system("adb shell ps")74 remove_forward(_uiautomator_port)75 uiautomator_process = excute_adb_process_daemon("shell uiautomator runtest DialogHandler_polling.jar -c com.github.uiautomatorstub.Stub",shell=True ,needStdout=False)76 # uiautomator_process = excute_adb_process_daemon("shell uiautomator runtest DialogHandler.jar -c com.github.uiautomatorstub.Stub", shell=True)77 #call_adb_shell("adb forward tcp:{0} tcp:{1} && adb shell uiautomator runtest uiautomator_stand_stub.jar -c com.github.uiautomatorstub.Stub".format(_uiautomator_port,_device_port))78 # call_adb_shell(["shell","uiautomator","runtest","/data/local/tmp/uiautomator_stand_stub.jar","-c","com.github.uiautomatorstub.Stub","--nohup"])#--nohup79 time.sleep(2)80 forward(_uiautomator_port, _device_port)81 # os.system("adb shell ps")82def init_uiautomator():83 """84 初始化uiautomator85 :return:86 """87 kill_uiautomator()88 file_path = os.path.split(os.path.realpath(__file__))[0]89 uiautomator_stub_path = os.path.abspath(90 os.path.join(file_path, "..","third","libs","uiAutomator","uiautomator-stub.jar"))91 adb=AdbTool()92 logger.debug(adb.cmd_wait("push",uiautomator_stub_path,"/data/local/tmp"))93 logger.debug("Start UIAutomator")94 uiautomator_process=adb.cmd("shell","uiautomator","runtest","uiautomator-stub.jar","-c","com.github.uiautomatorstub.Stub")95 time.sleep(2)96 adb.forward(_uiautomator_port,_device_port)97def _init():98 port = os.environ.get("UIAUTOMATORPORT")99 if port:100 return int(port)101 else:102 """103 本地,初始化UiAutomator104 """105 init_uiautomator()106 # init_uiautomator_with_dialoghandler()107 atexit.register(kill_uiautomator)108 return int(_uiautomator_port)109def get_uiautomator():110 if get_uiautomator.instance:111 return get_uiautomator.instance112 else:113 port=_init()114 get_uiautomator.instance = AutomatorDevice(None, port, os.environ.get("PLATFORM_IP", "127.0.0.1"), None)115 return get_uiautomator.instance...

Full Screen

Full Screen

uiautomator.py

Source:uiautomator.py Github

copy

Full Screen

...3#@创建日期:2020-06-29 23:24 4# Appium之uiautomator定位元素5# 元素定位方式有多种,Android也有自身独有的定位方式。下面就单独介绍其基于uiautomator定位元素的方法:6# 基本语法:7# driver.find_element_by_android_uiautomator(xx)8# 1).通过text文本定位语法:new UiSelector().text("text文本")9# # text10# loc_text = 'new UiSelector().text("图书")'11# driver.find_element_by_android_uiautomator(loc_text).click()12# 2).如果文本比较长,可以用textContains模糊匹配:new UiSelector().textContains("包含text文本")13# # textContains14# loc_textContains = 'new UiSelector().textContains("图")'15# driver.find_element_by_android_uiautomator(loc_textContains).click()16# 3).同样可以用textStartsWith是以某个文本开头来匹配:new UiSelector().textStartsWith("以text文本开头")17# # textStartsWith18# loc_textStart = 'new UiSelector().textStartsWith("图")'19# driver.find_element_by_android_uiautomator(loc_textStart).click()20# 4).也可以用正则表达式textMatches匹配:new UiSelector().textMatches("正则表达式")21#22# 2.resourceId 与by_id一样23# new UiSelector().resourceId("id")24# # resourceId25# loc_id = 'new UiSelector().resourceId("com.baidu.yuedu:id/webbooktitle")'26# driver.find_element_by_android_uiautomator(loc_id).click()27#28# 3.className 页面上的class属性一般不唯一,多半用在复数定位时候。此时定位相应下标29# new UiSelector().className("className")30# # className复数定位31# loc_class = 'new UiSelector().className("android.widget.TextView")'32# driver.find_elements_by_android_uiautomator(loc_class)[2].click()33#34# 4.description 也是用contenet - des属性定位35# new UiSelector().description("contenet-des属性")36#37# 5.组合定位38# 1).id与text属性组合39# # id+text40# id_text = 'resourceId("com.baidu.yuedu:id/webbooktitle").text("小说")'41# driver.find_element_by_android_uiautomator(id_text).click()42# 2).class与text属性组合43# # class+text44# class_text = 'className("android.widget.TextView").text("图书")'45# driver.find_element_by_android_uiautomator(class_text).click()46#47# 6.关系定位48# 1).父子定位childSelector49# 有时候不能直接定位某个元素,但是它的父元素很好定位,这时候就先定位父元素,通过父元素找儿子50# 如上定位书架:51# # 父子关系childSelector52# son = 'resourceId("com.baidu.yuedu:id/rl_tabs").childSelector(text("小说"))'53# driver.find_element_by_android_uiautomator(son).click()54# 2).兄弟定位fromParent55# 有时候父元素不好定位,但是跟他相邻的兄弟元素很好定位,这时候就可以通过兄弟元素,找到同一父56# 级元素下的子元素-如上定位书架:57# # 兄弟关系fromParent58# brother = 'resourceId("com.baidu.yuedu:id/lefttitle").fromParent(text("图书"))'59# driver.find_element_by_android_uiautomator(brother).click()...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

1# Copyright 2013 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4"""Generates test runner factory and tests for uiautomator tests."""5import logging6from pylib.uiautomator import test_package7from pylib.uiautomator import test_runner8def Setup(test_options):9 """Runs uiautomator tests on connected device(s).10 Args:11 test_options: A UIAutomatorOptions object.12 Returns:13 A tuple of (TestRunnerFactory, tests).14 """15 test_pkg = test_package.TestPackage(test_options.uiautomator_jar,16 test_options.uiautomator_info_jar)17 tests = test_pkg.GetAllMatchingTests(test_options.annotations,18 test_options.exclude_annotations,19 test_options.test_filter)20 if not tests:21 logging.error('No uiautomator tests to run with current args.')22 def TestRunnerFactory(device, shard_index):23 return test_runner.TestRunner(24 test_options, device, shard_index, test_pkg)...

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 ATX 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