1_weditor定位元素位置

WEditor

安装

github项目地址

https://github.com/openatx/weditor

安装代码

pip install --pre --upgrade weditor

显示如下,则安装成功

C:\Users\Administrator.PC-20170907TLUD>pip install --pre --upgrade weditor
Collecting weditor
  Downloading https://files.pythonhosted.org/packages/90/8b/f886be1af89c3444d688a1edf843b99532be72d6800ef6f2bbcc9c65ff77/weditor-0.0.4.dev9.tar.gz (1.2MB)
    100% |████████████████████████████████| 1.2MB 976kB/s
Collecting tornado>=4.3 (from weditor)
  Downloading https://files.pythonhosted.org/packages/e1/17/83cecc0ff2f200d9b7160e67726b2f419c53453bbe22929582fb08fe9122/tornado-5.1b1.tar.gz (516kB)
    100% |████████████████████████████████| 522kB 2.0MB/s
  Requested tornado>=4.3 from https://files.pythonhosted.org/packages/e1/17/83cecc0ff2f200d9b7160e67726b2f419c53453bbe22929582fb08fe9122/tornado-5.1b1.tar.gz#sha256=b640a110c98dfea03554120463bd4cd675f3245f15111c8893773620c03db15f (from weditor), but installing version 4.5.2
Collecting futures>=3.0.5 (from weditor)
  Downloading https://files.pythonhosted.org/packages/cc/26/b61e3a4eb50653e8a7339d84eeaa46d1e93b92951978873c220ae64d0733/futures-3.1.1.tar.gz
Requirement already up-to-date: six in c:\users\administrator.pc-20170907tlud\appdata\local\programs\python\python35\lib\site-packages (from weditor)
Collecting pillow (from weditor)
  Downloading https://files.pythonhosted.org/packages/ab/d2/d27a21bd3e64db1ca1dc7dc16026a16d77f5c3ffca9ec619eddeea7c47ce/Pillow-5.1.0-cp35-cp35m-win_amd64.whl (1.6MB)
    100% |████████████████████████████████| 1.6MB 747kB/s
Building wheels for collected packages: weditor, tornado, futures
  Running setup.py bdist_wheel for weditor ... done
  Stored in directory: C:\Users\Administrator.PC-20170907TLUD\AppData\Local\pip\Cache\wheels\43\29\78\ab5d01cff3bb4b396ec21f9c7b18b8c4448349bffa94d50137
  Running setup.py bdist_wheel for tornado ... done
  Stored in directory: C:\Users\Administrator.PC-20170907TLUD\AppData\Local\pip\Cache\wheels\66\c9\52\2cfc6fe979b8a3378aecfccea025b5f2303ad1ddd12846d57c
  Running setup.py bdist_wheel for futures ... done
  Stored in directory: C:\Users\Administrator.PC-20170907TLUD\AppData\Local\pip\Cache\wheels\f3\f9\c7\4fbf1faa6038faf183f6e3ea61f17a5f7eea5ab9a1dd7753fd
Successfully built weditor tornado futures
Installing collected packages: tornado, futures, pillow, weditor
  Found existing installation: tornado 4.5.2
    Uninstalling tornado-4.5.2:
      Successfully uninstalled tornado-4.5.2
  Found existing installation: Pillow 4.3.0
    Uninstalling Pillow-4.3.0:
      Successfully uninstalled Pillow-4.3.0
Successfully installed futures-3.1.1 pillow-5.1.0 tornado-5.1b1 weditor-0.0.4.dev9
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

运行如下代码

python -m weditor

则跳出浏览器,查看手机view

可以点击reload按钮更新查看的页面

WIFI网络链接可以直接输入设备IP(192.168.31.234),点击Connect按钮。

import uiautomator2 as u2
from time import sleep

d = u2.connect('192.168.31.234')

# 启动App
d.app_start("com.meizu.mzbbs")

# 搜索
d(resourceId="com.meizu.mzbbs:id/j0").click()

# 输入关键字
d(resourceId="com.meizu.mzbbs:id/p9").set_text("flyme")

# 搜索按钮
d(resourceId="com.meizu.mzbbs:id/tp").click()

sleep(2)

# 停止app
d.app_stop("com.meizu.mzbbs") 

app_start()和app_stop()用于启动和停止应用。

常用的定位方式:

ResourceId定位:

d(resourceId="com.meizu.mzbbs:id/tp").click()

Text定位:

d(text="精选").click()

Description定位:

d(description="..").click()

ClassName定位:

d(className="android.widget.TextView").click()

你可能感兴趣的:(自动化软件测试)