Appnium环境搭建和定位

Python+Appnium移动端自动化

1、环境搭建

https://nodejs.org/en/下载nodejs

https://bitbucket.org/appium/appium.app/downloads/

http://dl.google.com/android/android-sdk_r23.0.2-windows.zip 下载SDK,更新几个包

设置各种环境变量

Appnium环境搭建和定位_第1张图片

Appnium环境搭建和定位_第2张图片

 

打开开发人员选项——USB调试

Appnium环境搭建和定位_第3张图片

 

第一个移动自动化程序

# -*-coding:gbk-*-
from appium import webdriver
import time
desired_caps={
    'platformName':'Android',
    'deviceName':'SNMBB18314511026',
    'platformVersion':'8.0',
    'appPackage':'com.taobao.taobao',
    'appActivity':'com.taobao.tao.welcome.Welcome'
}
driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(5)
driver.find_element_by_id("com.taobao:id/home_searchedit").click()

2、定位入门

查看当前运行的app包信息

adb shell dumpsys window w |findstr \/ |findstr name=

查看appActivity信息:

方法1:

adb logcat >log.txt

打开APP

CTRL+C  关闭日志

打开log日志,查看

方法2:

后缀名改为rar,解压中AndroidManifest.xml中查找manifest

Appnium环境搭建和定位_第4张图片

法三:

aapt dump badging C:\Users\Administrator\base.apk

UI Automator工具的运用

(1)第一个按钮:层级关系

Appnium环境搭建和定位_第5张图片

(2)第二个按钮:各个元素的属性

Appnium环境搭建和定位_第6张图片

3、定位方法

(1)、ID定位:resource-id、id、name

eg:淘宝的搜索框和搜索按钮

(2)、class、text定位

(3)、xpath定位

绝对路径

相对路径

(4)坐标定位       Click A Point[x|y]

4、框架扩展(模仿廖雪峰老师的框架)

 

import unittest
from appium import webdriver
import time


class TestBaiduCloudApp(unittest.TestCase):
   def setUp(self):

      desired_caps = {
         'platformName': 'Android',
         'deviceName': 'SNMBB18314511026',
         'platformVersion': '8.0',
         'appPackage': 'com.baidu.netdisk',
         'appActivity': 'com.baidu.netdisk.ui.Navigate'
      }
      self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

   def test_login(self):
      driver=self.driver
      time.sleep(10)
      driver.find_element_by_id("com.baidu.netdisk:id/loginBtn").click()
      time.sleep(10)
      assert driver.find_element_by_id("login-otherLogin").text == "登录其他帐号"

   def tearDown(self):
      pass


if __name__ == "__main__":
   unittest.main()

遗留问题:driver.find_element_by_id("login-otherLogin")没有定位到

 

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