zoukankan      html  css  js  c++  java
  • Appium 自动化测试(8) -- Appium Python client -- API

    最好的学习方法,就是看源码!

    在  appiumwebdriverwebdriver.py ,新增了两个封装好定位安卓元素的方法,如  find_element_by_accessibility_id 与 find_element_by_android_uiautomator

    如下图,定位“一起玩”tab页:

    一、根据UIAutomator定位元素

        def test_find_element(self):
            self.driver.wait_activity('com.yy.mobile.ui.home.MainActivity',30)
            # text 属性的方法
            el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("一起玩")')
            self.assertIsNotNone(el)
            e2 = self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("起玩")')
            self.assertIsNotNone(e2)
            e3 = self.driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("一起")')
            self.assertIsNotNone(e3)
            e4 = self.driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^一起.*")')
            self.assertIsNotNone(e4)
            # class属性的方法
            e5 = self.driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("一起玩")')
            self.assertIsNotNone(e5)
            # resourceId属性的方法
            e6 = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.yy.mobile.plugin.main:id/tab_tab_btn")')
            self.assertIsNotNone(e6)

    二、根据accessibility_id定位

        def find_element_by_accessibility_id(self, id):
            """Finds an element by accessibility id.
    
            :Args:
             - id - a string corresponding to a recursive element search using the
             Id/Name that the native Accessibility options utilize
    
            :Usage:
                driver.find_element_by_accessibility_id()
            """
            return self.find_element(by=By.ACCESSIBILITY_ID, value=id)

    对于 Android 就是 content-description

    对于 iOS 就是 accessibility identifier

     三、看源码可知,Appium 中的Webdriver是Selenium中的webdirver.Remote的子类,所以更多的API,可是在Selenium中寻找

    ***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***
  • 相关阅读:
    java学习笔记3
    java学习笔记 2
    linux用户登录指定目录
    [Jenkins 新插件] 兼容阿里开发手册 (P3C) 的火线插件安装使用教程
    Color a Tree HDU
    网络流初步
    K度限制MST poj 1639
    曼哈顿距离MST
    ACM Amman Collegiate Programming Contest(7.22随机组队娱乐赛)
    HDU Distinct Values
  • 原文地址:https://www.cnblogs.com/guanfuchang/p/9122370.html
Copyright © 2011-2022 走看看